info@ektanjali.com +91 99276-99286

CakePHP 3.x User Management Premium Plugin Version 3.3.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 any function you should get results from database in following way e.g. in index function

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

3. Now in template ctp 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/plugins/Usermgmt/src/Controller/UsersController.php
Index View yourapp/plugins/Usermgmt/src/Template/Users/index.ctp
Index View yourapp/plugins/Usermgmt/src/Template/Element/all_users.ctp