如何在 CakePHP 中对多个结果进行分页?

发布于 2024-09-13 03:10:26 字数 246 浏览 8 评论 0原文

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

编辑:
我发现它不能这样做的一个原因是因为分页助手将从控制器/操作获取其 URL,然后在末尾附加其参数。 如果它从地址栏中提取 url,拥有自己的唯一变量,然后执行 str_replace 来获取下一个要导航的位置(如果您已经分页),或者如果它不存在则追加它。 现在,我正在考虑重写分页助手来支持此功能,但我不确定我是否需要这样做,或者他们是否已经支持此功能,而我做错了

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

前事休说 2024-09-20 03:10:27

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

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

在您的视图中:

// 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'));

要点是将您的模型名称输入到控制器的分页方法和分页器的链接方法(排序、上一个、下一个)中。

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).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文