views:

54

answers:

2

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

A: 

You mean results from 2 different models on one page?

Nigel
A: 

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

Jamal Aziz