How to Limit the paginate in cakephp

AnNaMaLaI picture AnNaMaLaI · May 27, 2011 · Viewed 16.5k times · Source

How to Limit the paginate in cakephp ?

Assume that i have 400 records.
I need to get only 25 records from 50th record to 75th record and need to display 5 records per page.
How i can do this in paginate ?

Sample Code:

        $this->paginate = array(
                'contain'=>array('User'),
                'recursive' => 2,
                'order' => array('Profile.winning' => 'DESC'),
                'limit' =>5

            );

Answer

pawelmysior picture pawelmysior · May 27, 2011

You can set conditions for the pagination.

function listRecords()
  {
  $this->paginate = array(
    'conditions' => array('Model.id >=' => 50, 'Model.id <=' => 75),
    'limit' => 5
    );
  $this->paginate('Model');
  );

EDIT:

A solution from here:

$this->paginate = array(
  'limit' => 20,
  'totallimit' => 1000
  );

And then in the Model:

public function paginateCount($conditions = null, $recursive = 0, $extra = array())
  {
  if( isset($extra['totallimit']) ) return $extra['totallimit'];
  }