PR

CakePHP – ACL再入門(3)

やっぱりACLは難しい。整理の意味も含めてもう一度入門しておく。(今回はCakePHP1.3.2です)

データベース、モデルと来たので、次はビューの準備。まずはGroupから。

スポンサードリンク

views/groups/index.ctp

<div>
<h2><?php __('Groups');?></h2>
<p>
<?php
echo $paginator->counter(array(
'format' => __('Page %page% of %pages%, showing %current% records out of %count% total, starting on record %start%, ending on %end%', true)
));
?></p>
<table cellpadding="0" cellspacing="0">
<tr>
 <th><?php echo $paginator->sort('id');?></th>
 <th><?php echo $paginator->sort('name');?></th>
 <th><?php echo $paginator->sort('created');?></th>
 <th><?php echo $paginator->sort('modified');?></th>
 <th><?php __('Actions');?></th>
</tr>
<?php
$i = 0;
foreach ($groups as $group):
 $class = null;
 if ($i++ % 2 == 0) {
  $class = '';
 }
?>
 <tr<?php echo $class;?>>
  <td>
   <?php echo $group['Group']['id']; ?>
  </td>
  <td>
   <?php echo $group['Group']['name']; ?>
  </td>
  <td>
   <?php echo $group['Group']['created']; ?>
  </td>
  <td>
   <?php echo $group['Group']['modified']; ?>
  </td>
  <td>
   <?php echo $html->link(__('View', true), array('action' => 'view', $group['Group']['id'])); ?>
   <?php echo $html->link(__('Edit', true), array('action' => 'edit', $group['Group']['id'])); ?>
   <?php echo $html->link(__('Delete', true), array('action' => 'delete', $group['Group']['id']), null, sprintf(__('Are you sure you want to delete # %s?', true), $group['Group']['id'])); ?>
  </td>
 </tr>
<?php endforeach; ?>
</table>
<div>
 <?php echo $paginator->prev('<< '.__('previous', true), array(), null, array('class'=>'disabled'));?>
 |  <?php echo $paginator->numbers();?>
 <?php echo $paginator->next(__('next', true).' >>', array(), null, array('class' => 'disabled'));?>
</div>
</div>
<div>
 <ul>
  <li><?php echo $html->link(__('New Group', true), array('action' => 'add')); ?></li>
  <li><?php echo $html->link(__('List User', true), array('controller' => 'users')); ?></li>
 </ul>
</div>

views/groups/view.ctp

<div>
<h2><?php  __('Group');?></h2>
 <dl><?php $i = 0; $class = '';?>
  <dt<?php if ($i % 2 == 0) echo $class;?>><?php __('Id'); ?></dt>
  <dd<?php if ($i++ % 2 == 0) echo $class;?>>
   <?php echo $group['Group']['id']; ?>
   &nbsp;
  </dd>
  <dt<?php if ($i % 2 == 0) echo $class;?>><?php __('Name'); ?></dt>
  <dd<?php if ($i++ % 2 == 0) echo $class;?>>
   <?php echo $group['Group']['name']; ?>
   &nbsp;
  </dd>
  <dt<?php if ($i % 2 == 0) echo $class;?>><?php __('Created'); ?></dt>
  <dd<?php if ($i++ % 2 == 0) echo $class;?>>
   <?php echo $group['Group']['created']; ?>
   &nbsp;
  </dd>
  <dt<?php if ($i % 2 == 0) echo $class;?>><?php __('Modified'); ?></dt>
  <dd<?php if ($i++ % 2 == 0) echo $class;?>>
   <?php echo $group['Group']['modified']; ?>
   &nbsp;
  </dd>
 </dl>
</div>
<div>
 <ul>
  <li><?php echo $html->link(__('List Groups', true), array('action' => 'index')); ?> </li>
  <li><?php echo $html->link(__('Edit Group', true), array('action' => 'edit', $group['Group']['id'])); ?> </li>
  <li><?php echo $html->link(__('Delete Group', true), array('action' => 'delete', $group['Group']['id']), null, sprintf(__('Are you sure you want to delete # %s?', true), $group['Group']['id'])); ?> </li>
  <li><?php echo $html->link(__('New Group', true), array('action' => 'add')); ?> </li>
 </ul>
</div>

views/groups/add.ctp

<div>
<?php echo $form->create('Group');?>
 <fieldset>
   <legend><?php __('Add Group');?></legend>
 <?php
  echo $form->input('name');
 ?>
 </fieldset>
<?php echo $form->end('Submit');?>
</div>
<div>
 <ul>
  <li><?php echo $html->link(__('List Groups', true), array('action' => 'index'));?></li>
 </ul>
</div>

views/groups/edit.ctp

<div>
<?php echo $form->create('Group');?>
 <fieldset>
   <legend><?php __('Edit Group');?></legend>
 <?php
  echo $form->input('id');
  echo $form->input('name');
 ?>
 </fieldset>
<?php echo $form->end('Submit');?>
</div>
<div>
 <ul>
  <li><?php echo $html->link(__('List Groups', true), array('action' => 'index'));?></li>
  <li><?php echo $html->link(__('Delete', true), array('action' => 'delete', $form->value('Group.id')), null, sprintf(__('Are you sure you want to delete # %s?', true), $form->value('Group.id'))); ?></li>
 </ul>
</div>

コメント