sorting - sort by alphabetical field -


i need alphabetical order of how name list. need while occupied pager cakephp not be. thought in order field (in case name) desc , asc not work me in case.

in controller :

$conditions = array('active !=' => -1, 'not' => array('role_id' => 2)); $users = $this->paginate('user', $conditions); $this->set(compact('users','filter')); 

in 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 $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> 

add following after conditions

$this->user->order(                    array('user.username asc') //use whatever field want sort                    ); 

Comments