Loading…

How to use pagination in cakePHP?

1. Open your controller file & put below code.
public $paginate = [
'limit' => 10,
'order' => [
'Users.name' => 'asc'
]
];



2. After this now load Paginator in initialize (). public function initialize()
{
parent::initialize();
$this->loadComponent('Paginator');
}



3. Please set Paginate in Index function.
public function index() {
$this->layout=false;
$details=$this->Users->find('all');
$this->set('users', $this->paginate($details));
}



4. You can write this code in your "index.ctp" page.
echo $this->Paginator->prev('< ' . __('previous'), array('tag' => 'li', 'currentTag' => 'a', 'currentClass' => 'disabled'), null, array('class' => 'prev disabled'));

echo $this->Paginator->numbers(array('separator' => '','tag' => 'li', 'currentTag' => 'a', 'currentClass' => 'active'));
echo $this->Paginator->next(__('next').' >', array('tag' => 'li', 'currentTag' => 'a', 'currentClass' => 'disabled'), null, array('class' => 'next disabled'));
?>

 

Suggest An Answer

No suggestions avaliable!

Latest post from CakePHP interview questions

Ask Question