I want to do something very direct and simple. I want two different sets of paginated data on one page. Two different sets depend on different models. For discussion, we will say that they are Image and Item .
I can configure two pagers for two models and get the correct set of objects. I can get the correct pager links. But when it comes to parameter references, both pagers read the parameters and assume that they apply to them.
It looks like this:
$this->paginate = array ( 'Item'=>array( 'conditions'=>array('user_id'=>$id), 'limit' => 6, 'order' => array( 'Item.votes'=>'desc', 'Item.created'=>'desc' ), 'contain'=>array( 'User', 'ItemImage' => array ( 'order'=>'ItemImage__imageVotes desc' ) ) ), 'Image'=>array( 'limit'=>6, 'contain'=>array( 'User', 'ItemImage'=>array('Item'), ), 'order'=>array( 'Image.votes'=>'desc', 'Image.views'=>'desc' ), 'conditions'=>array( 'Image.isItemImage'=>1, 'Image.user_id'=>$id ) ) ); $this->set('items', $this->paginate('Item')); $this->set('images', $this->paginate('Image'));
This is in the controller. In the view, I have a sort of links that look like this:
<div class="control"><?php echo $this->Paginator->sort('Newest', 'Image.created', array('model'=>'Image')); ?></div>
However, this gives a link that looks like this:
http://localhost/profile/37/page:1/sort:Image.created/direction:asc
There is nothing to talk about which model I intend to sort. So when I click on the link, it tries to sort both models using Image.created . The result is an error because Item cannot be sorted by Image.created . Is there something I'm doing wrong? Or is it something that CakePHP paginator is not supported?