2010-07-07 65 views
0

我正在做一些關於在CakePHP 1.26中分頁的自學習。在CakePHP中與hasmany關聯分頁

在PostsController,我有這樣的代碼:

$this->set('views', $this->Testing->Reply->findAllBypost_id($id)); 

我試圖改變爲分頁目的,
代碼,這是我已經嘗試了:

$this->paginate=array('conditions'=>array('Reply.post_id'=>'0'), 'limit' => 4); 
$w = $this->paginate($this->Testing->Reply); 
$this->set('views', $w); 

我不知道這是否是最好的方式,請評論。

回答

1

看起來對我來說,確保您在視圖中使用paginator助手,以便能夠最大程度地使用分頁。

你可以使這一行更少,如果post_id是一個int,那麼使用一個實際的int。我也不會把你的視圖變量稱爲與實際物體或碎片相關的東西...

$this->paginate=array('conditions'=>array('Reply.post_id'=> 0), 'limit' => 4); 
$this->set('data', $this->paginate($this->Testing->Reply));