Wednesday 29 April 2015

Simple Cakephp Pagination


Cakephp provides a quick an easy way to paginate data.
In the controller we start by creating the pagination condition as given below :
  1. public $paginate = array(
  2. 'limit' => 10,
  3. 'order' => array(
  4. 'Model.fieldname' => 'asc'
  5. )
  6. );
  7. public function listdetails(){
  8. $variable = $this->paginate("Model", array('Model.fieldname' =>'1'));
  9. }

Write the following code in the view where pagination has to be displayed here the view name is listdetails.ctp
  1. <?php
  2. echo $this->paginator->prev('<<Previous', null, null, null);
  3. echo $this->paginator->numbers();echo "&nbsp;|";
  4. echo $this->paginator->next('Next>>', null, null, null);
  5. ?>

For such more Blogs you can visit to http://findnerd.com/NerdDigest


No comments:

Post a Comment