开发者

How to paginate multiple results in CakePHP?

开发者 https://www.devze.com 2023-01-10 12:16 出处:网络
How can I use the paginatation helper in cakePHP to show more than one result set on the same page? They would page independently.

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

0

精彩评论

暂无评论...
验证码 换一张
取 消