2014-09-06 171 views
0

我是新來CakePHP的,我的分頁不工作..Cakephp分頁不起作用?

我的控制器代碼:

$this->paginate = array('Favourite' =>array('limit' => '1','conditions'=>array('user_id'=>$id))); 
$cat_data = $this->paginate('Favourite'); 
$this->set('fav_data',$cat_data); 

我的視圖代碼:

<!---Code for pagination --> 
<div> 
<?php echo $this->Paginator->prev('', null, null, array('class' => 'pdisable','escape' => false)); ?> 
<div class="numbers"><?php echo $this->Paginator->numbers(); ?>&nbsp;&nbsp;Pages: <?php echo $this->Paginator->counter(); ?></div> 
<?php echo $this->Paginator->next('', null, null, array('class' => 'ndisable','escape' => false)); ?> 
</div> 

基礎上,它不顯示一個結果限制我給出..它顯示所有的記錄。

回答

1

當你試圖讓使用您的代碼此行的分頁記錄:

$cat_data = $this->paginate('Favourite');

你實際上是重新聲明的PAGINATE設置的第二次,只是沒了指定的限制或條件。您需要使用Paginator組件類以及事先聲明的分頁設置。

在您的代碼:

//此處是您在聲明PAGINATE設置一個時間。

$this->paginate = array('Favourite' =>array('limit'=>'1','conditions'=>array('user_id'=>$id)));

//在這裏再次重複聲明它們,只有不與指定的限制或條件。這有效地覆蓋了你所做的第一個設置聲明。

$cat_data = $this->paginate('Favourite');

$this->set('fav_data',$cat_data);

變化:

$cat_data = $this->paginate('Favourite');

要:

$cat_data = $this->Paginator->paginate('Favourite');

所以控制器代碼建議立即進行刪除d看起來像:

//declare settings without conditions. 
$this->paginate = array(
    'limit' => 1 
); 

//use above settings to pull the paginated results. 
//be sure to add the conditions you had in the settings before to the 2nd parameter of the `paginate()` function. 
$this->set('fav_data', $this->Paginator->paginate('Favourite', array('user_id' => $id)));