2012-06-13 89 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