如何在CakePHP中分页多个结果? [英] How to paginate multiple results in CakePHP?

查看:109
本文介绍了如何在CakePHP中分页多个结果?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在cakePHP中使用paginatation助手在同一页面上显示多个结果集?他们会独立页面。



编辑:

我发现一个原因,为什么它不能这样做是因为分页助手会从控制器/操作然后在其末尾附加其参数。
如果它从地址栏拉取url,有自己的唯一变量,然后做了一个str_replace如果你已经分页,得到下一个导航到,或者如果它不存在则追加它。
现在,我正在考虑重写分页助手来支持这个功能,但我不知道如果我需要,或者如果他们已经支持这个,我做错了

解决方案

这里是我的解决方案。在您的控制器中:

  function index(){
//您的默认模型
$ this-> ; set('model1',$ this-> paginate());
// model2的分页
$ this-> set('model2',$ this-> paginate('Model2'));
}

在您的视图中:

  //显示您的model1数据,然后为prev和next 
echo $ paginator-> prev($ options = array('model'=>'Model1 '));
echo $ paginator-> next($ options = array('model'=>'Model1'));


//显示你的model2数据,然后为prev和next
echo $ paginator-> prev($ options = array('model'=>'Model2 '));
echo $ paginator-> next($ options = array('model'=>'Model2'));点是将模型名称输入到Controller的paginate方法和Paginator的链接方法(sort,prev,下一步)。


How can I use the paginatation helper in cakePHP to show more than one result set on the same page? They would page independently.

EDIT:
I found out one reason why it can't do that is because the pagination helper would get its URL from the controller/action and then appends its parameters at the end. If it pulled the url from the address bar, had its own unique variable and then did an str_replace to get the next one to navigate to if you've already paged, or append it if it doesn't exist. Right now, I'm thinking of rewriting the pagination helper to support this feature, but I'm not sure if I would need to or if they already support this and I'm doing it wrong

解决方案

Here is my solution. In your controller :

function index(){
    // Your default model
    $this->set('model1', $this->paginate());
    // Pagination for model2
    $this->set('model2', $this->paginate('Model2'));
}

In your view :

// Display your model1 data, and then for prev and next 
echo $paginator->prev($options = array('model' => 'Model1'));
echo $paginator->next($options = array('model' => 'Model1'));


// Display your model2 data, and then for prev and next 
echo $paginator->prev($options = array('model' => 'Model2'));
echo $paginator->next($options = array('model' => 'Model2'));

The point is input your model name to Controller's paginate method and to Paginator's link method (sort, prev, next).

这篇关于如何在CakePHP中分页多个结果?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆