0

我在这里为我的项目使用 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); 

使用它,我得到一个数组的结果。它不会对其执行分页。

我怎样才能得到这个结果的分页?

4

2 回答 2

0

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

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

于 2010-08-04T12:36:26.350 回答
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'))

祝你好运

于 2011-07-13T12:11:42.573 回答