2012-06-13 91 views
0

我目前正在嘗試在兩個不同的模型上設置分頁。 在Controller類我做如下:cakephp 2.0分頁問題

var $paginate = array(
     'Model1' => array('limit' => 10, 'recursive' => 0, 'model' => 'Model1, 'order' => array('field1' => 'ASC'), 'paramType' => 'querystring'), 
     'Model2' => array('limit' => 10, 'recursive' => 0, 'model' => 'Model2', 'order' => array('field2' => 'ASC'), 'paramType' => 'querystring') 
    ); 

    function view($id = null) { 

     // ... 

     $models1 = $this->paginate('Model1', array('Model1.model_id => $id));   
     if ($models1) { 
      $this->set('models1', $models1); 
     } 
     $models2 = $this->paginate('Model2', array('Model2.model_id => $id)); 
     if ($models2) { 
      $this->set('models2', $models2); 
     } 
    } 

在視圖中,鏈接使用

<?php echo $this->Paginator->numbers(array('model' => 'Model1')); ?> 
    <?php echo $this->Paginator->numbers(array('model' => 'Model2')); ?> 

其結果是,我得到的打印的頁數生產,但鏈接錯誤。

  1. id被忽略,即代替controller/action/id?page= ...,我得到controller/action?page= ...
  2. 這部分鏈接sort=Model1.field1&direction=ASC也不起作用。 我可以用sort=field1&direction=ASC打開頁面。但是,如果對第一個或第二個模型進行排序,該如何區分呢?

順便說一句,所有這些在使用CakePHP 1.3時運行良好。

+0

爲了得到'id'中的鏈接,你需要有'$這個 - >型號 - > ID = $ id',然後調用'paginate'函數。但我仍然有類似的問題,鏈接... – nil

回答

0

您已經在兩個通話分頁Model1,肯定是第二個應該是:

$models2 = $this->paginate('Model2', ... 
+0

對不起,這是一個錯字 – nil