1.

How to use pagination in cakePHP?

Answer»

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'));
?>

 



Discussion

No Comment Found