info@ektanjali.com +91 99276-99286

CakePHP 2.x User Management Premium Plugin Version 2.2.x

Sorting

Sorting is very easy in Cake Php please make sure sorting works with CakePHP pagination.

How to use sorting in Cake Php
1. set pagination variable in your controller for e.g. in UsersController.php

public $paginate = array(
            'limit' => 25
        );


2. Now in any function you should get results from Database in following way for e.g. in index function

$this->paginate = array('limit' => 10, 'order'=>'User.id desc');
$users = $this->paginate('User');

$this->set('users', $users);

3. Now in View file you should use table headers in following way-

<th><?php echo $this->Paginator->sort('User.first_name'__('Name')); ?></th>
Now this table column for Name becomes sort-able.

For more information see
Users Controller yourapp/app/Plugin/Usermgmt/Controller/UsersController.php
Index View yourapp/app/Plugin/Usermgmt/View/Elements/all_users.ctp