info@ektanjali.com +91 99276-99286

CakePHP 3.x User Management Premium Plugin Version 3.1.x

Pagination

 How to use pagination 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 you should add pagination element in following way e.g. in index.ctp after the results table

<?php if(!empty($users)) {
echo $this->element('Usermgmt.pagination', ['paginationText'=>__('Number of Users')]);
}?>

where
$users is result variable, set from controller's index function.
'Usermgmt.pagination' is a pagination element location is yourapp/plugins/Usermgmt/src/Template/Element/pagination.ctp.
'paginationText' is a pagination text to be displayed on pagination bar.

 

For more information see
Users Controller yourapp/plugins/Usermgmt/src/Controller/UsersController.php
Index View yourapp/plugins/Usermgmt/src/Template/Users/index.ctp
Pagination Element yourapp/plugins/Usermgmt/src/Template/Element/pagination.ctp