info@ektanjali.com +91 99276-99286

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

Sorting

 How to use sorting in plugin and outside plugin

1. Set pagination variable in your controller e.g. in UsersController.php

public $paginate = ['limit'=>25];

2. Now in controller's action you should get results from database in following way e.g. in index function

$this->paginate = ['limit'=>10, 'order'=>['User.id'=>'DESC']];
$users = $this->paginate('User');
$this->set(compact('users'));

3. Now in template file should use table headers in following way

<th><?php echo $this->Paginator->sort('Users.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/Users/index.php
Index View yourapp/app/Plugin/Usermgmt/View/Users/all_users.php