How to paginate multiple results in CakePHP?

醉酒当歌 提交于 2020-01-02 00:11:08

问题


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


回答1:


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



来源:https://stackoverflow.com/questions/3394524/how-to-paginate-multiple-results-in-cakephp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!