How to make pagination of result in CakePHP
I am using CakePHP for my project in this here I get the result from the join query but by this I wanna make pagination on this result by using my way it's not possible.
This is my code:
$id= $this->Session->read('id开发者_运维问答');
$this->layout='ui_defualt';
$options['joins'] = array(array('table' => 'fj_bounty_watches','conditions' => array('fj_bounty_watches.nBountyID = FjBounty.id')));
$options['conditions'] = array('fj_bounty_watches.nHeadHunterID' =>$id);
$watchedbounty = $this->FjBounty->find('all', $options);
Using this, I get the result as an array. It does not perform pagination on it.
How can I get pagination on this result?
You should get paginated results if you use the correct setup:
http://book.cakephp.org/view/1232/Controller-Setup
you can set the pagination parameters just like with the find
method:
YourModel Controller:
$this->paginate['YourModel'] = array( 'recursive' => -1,
'fields' => array('YourModel.*','OtherModel.*'),
'joins' => $joins, // an array of joins
'order' => array('YourModel.creation'),
'conditions'=> $conditions,
'limit' => 10
);
$this->set('myPaginatedList', $this->paginate('YourModel'));
and also, i see that your join array is not quite respecting the naming convention, it should be something like:
array( 'table' => 'fj_bounty_watches',
'alias' => 'FjBountyWatches',
'type' => 'INNER', // or left, or right
'conditions' => array('FjBountyWatches.nBountyID = FjBounty.id'))
Good Luck
精彩评论