如何在CakePHP中对结果进行分页

时间:2010-07-07 05:21:17

标签: cakephp-1.3

我在这里使用CakePHP作为我的项目我从连接查询得到了结果但是我想通过使用我的方式对这个结果进行分页,这是不可能的。

这是我的代码:

$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); 

使用它,我得到一个数组的结果。它没有对它进行分页。

如何对此结果进行分页?

2 个答案:

答案 0 :(得分:0)

如果使用正确的设置,您应该获得分页结果:

http://book.cakephp.org/view/1232/Controller-Setup

答案 1 :(得分:0)

您可以像使用find方法一样设置分页参数:

YourModel控制器:

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

而且,我发现你的连接数组不太符合命名约定,它应该是这样的:

array(  'table' => 'fj_bounty_watches',
        'alias' => 'FjBountyWatches',
        'type' => 'INNER', // or left, or right
        'conditions' => array('FjBountyWatches.nBountyID = FjBounty.id'))

祝你好运

相关问题