2010-07-07 28 views
0

我在這裏使用CakePHP作爲我的項目在這裏,我從加入查詢中得到結果,但是由於我想通過使用我的方式對此結果進行分頁,這是不可能的。如何在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); 

利用這一點,我得到的結果作爲數組。它不執行分頁。

我怎樣才能得到這個結果的分頁?

回答

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

還有,我看到你的連接數組i不是很尊重的命名規則,它應該是這樣的:

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

好運

相關問題