PR

CakePHP – ACL再入門(4)

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

データベース、モデルと来たので、次はビューの準備。次にUser。

スポンサードリンク

views/users/index.ctp

<div>
<h2><?php __('Users');?></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('username');?></th>
 <th><?php echo $paginator->sort('password');?></th>
 <th><?php echo $paginator->sort('group_id');?></th>
 <th><?php echo $paginator->sort('created');?></th>
 <th><?php echo $paginator->sort('modified');?></th>
 <th><?php __('Actions');?></th>
</tr>
<?php
$i = 0;
foreach ($users as $user):
 $class = null;
 if ($i++ % 2 == 0) {
  $class = '';
 }
?>
 <tr<?php echo $class;?>>
  <td>
   <?php echo $user['User']['id']; ?>
  </td>
  <td>
   <?php echo $user['User']['username']; ?>
  </td>
  <td>
   <?php echo $user['User']['password']; ?>
  </td>
  <td>
   <?php echo $user['Group']['name']; //echo $user['User']['group_id']; ?>
  </td>
  <td>
   <?php echo $user['User']['created']; ?>
  </td>
  <td>
   <?php echo $user['User']['updated']; ?>
  </td>
  <td>
   <?php echo $html->link(__('View', true), array('action' => 'view', $user['User']['id'])); ?>
   <?php echo $html->link(__('Edit', true), array('action' => 'edit', $user['User']['id'])); ?>
   <?php echo $html->link(__('Delete', true), array('action' => 'delete', $user['User']['id']), null, sprintf(__('Are you sure you want to delete # %s?', true), $user['User']['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 User', true), array('action' => 'add')); ?></li>
  <li><?php echo $html->link(__('List Group', true), array('controller' => 'groups')); ?></li>
 </ul>
</div>

views/users/view.ctp

<div>
<h2><?php  __('User');?></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 $user['User']['id']; ?>
   &nbsp;
  </dd>
  <dt<?php if ($i % 2 == 0) echo $class;?>><?php __('Username'); ?></dt>
  <dd<?php if ($i++ % 2 == 0) echo $class;?>>
   <?php echo $user['User']['username']; ?>
   &nbsp;
  </dd>
  <dt<?php if ($i % 2 == 0) echo $class;?>><?php __('Group Id'); ?></dt>
  <dd<?php if ($i++ % 2 == 0) echo $class;?>>
   <?php echo $user['User']['group_id']; ?>
   &nbsp;
  </dd>
  <dt<?php if ($i % 2 == 0) echo $class;?>><?php __('Created'); ?></dt>
  <dd<?php if ($i++ % 2 == 0) echo $class;?>>
   <?php echo $user['User']['created']; ?>
   &nbsp;
  </dd>
  <dt<?php if ($i % 2 == 0) echo $class;?>><?php __('Updated'); ?></dt>
  <dd<?php if ($i++ % 2 == 0) echo $class;?>>
   <?php echo $user['User']['updated']; ?>
   &nbsp;
  </dd>
 </dl>
</div>
<div>
 <ul>
  <li><?php echo $html->link(__('List Users', true), array('action' => 'index')); ?> </li>
  <li><?php echo $html->link(__('Edit User', true), array('action' => 'edit', $user['User']['id'])); ?> </li>
  <li><?php echo $html->link(__('Delete User', true), array('action' => 'delete', $user['User']['id']), null, sprintf(__('Are you sure you want to delete # %s?', true), $user['User']['id'])); ?> </li>
  <li><?php echo $html->link(__('New User', true), array('action' => 'add')); ?> </li>
 </ul>
</div>

views/users/add.ctp

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

views/users/edit.ctp

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

views/users/login.ctp

<?php
$session->flash('auth');
echo $form->create('User', array('action' => 'login'));
echo $form->inputs(array(
 'legend' => __('Login', true),
 'username',
 'password'
));
echo $form->end('Login');
?>

コメント

タイトルとURLをコピーしました