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')); ?>
其结果是,我得到的打印的页数生产,但链接错误。
- 的
id
被忽略,即代替controller/action/id?page= ...
,我得到controller/action?page= ...
。 - 这部分链接
sort=Model1.field1&direction=ASC
也不起作用。 我可以用sort=field1&direction=ASC
打开页面。但是,如果对第一个或第二个模型进行排序,该如何区分呢?
顺便说一句,所有这些在使用CakePHP 1.3时运行良好。
为了得到'id'中的链接,你需要有'$这个 - >型号 - > ID = $ id',然后调用'paginate'函数。但我仍然有类似的问题,链接... – nil