1
我需要列表名稱的字母順序。當我佔用尋呼機CakePHP時我需要做的事情,但我不能。我認爲按字段順序排列(在這個例子中是名字),所以DESC和ASC在任何情況下都不起作用。按字母順序排列
在控制器:
$conditions = array('active !=' => -1, 'NOT' => array('role_id' => 2));
$users = $this->paginate('User', $conditions);
$this->set(compact('users','filter'));
在View:
<div class="row">
<table class="table table-striped table-hover table-condensed col-lg-12">
<thead>
<tr>
<th>#</th>
<th><?=$this->Paginator->sort('username', h(__('User')));?></th>
<th><?=$this->Paginator->sort('name');?></th>
<th><?=$this->Paginator->sort('email');?></th>
<th><?=$this->Paginator->sort('created', h(__('Registration date')));?></th>
<th><?=$this->Paginator->sort('active', h(__('Status')));?></th>
</tr>
</thead>
<tbody>
<?php
$offset = $this->Paginator->counter(array('format' => '{:start}'));
foreach($users as $user) {
echo '<tr onclick="window.location.href=\''.$this->Html->url(array('controller'=>'users','action'=>'view',
$user['User']['id'])).'\'">'.
'<td>'.($offset++).'</td>'.
'<td>'.h($user['User']['username']).'</td>'.
'<td>'.h($user['User']['name'].' '.$user['User']['father_surname'].' '.$user['User']['mother_surname']).'</td>'.
'<td>'.str_replace('@','[at]',h($user['User']['email'])).'</td>'.
'<td>'.$this->Time->format('d-m-Y H:i',strtotime($user['User']['created'])).'</td>'.
'<td>';
if ($user['User']['active'] == 1)
echo '<span class="label label-success">'.h(__('Active')).'</span>';
else
echo '<span class="label label-warning">'.h(__('Blocked')).'</span>';
echo '</td>'.
'</tr>';
}
?>
</tbody>
</table>
</div>