I have pagination working fine for when $this->paginate is called once in an action, but it does not appear to be very good support for multiple calls. Here is what I'm looking to do ...
function admin_index() {
$published = $this->pagination('Post', array('status'=>1));
$unpublished = $this->pagination('Post', array('status'=>0));
$this->set('published', $published);
$this->set('unpublished', $unpublished);
}
A simplified version of my view would be:
<h1>Unpublished Posts</h1>
<?php echo $this->element('table', array('posts'=>$unpublished)); ?>
<h1>Published Posts</h1>
<?php echo $this->element('table', array('posts'=>$published)); ?>
Simple, and I can re-use the same element to display different types of data. Is there really no way around paginating each of these table separately other than jquery table sorter / hacks to Cakephp?
I understand that I could stick all the data in one table and then just use sorting to differentiate between the statuses, but I wanted to check if I was missing something first.
Since there was not much activity on this, I went ahead and did the reasonable thing and figured out a workaround. Below is what I came up with:
Controller:
Views: (simplified)
index.ctp
elements/posts_table_paginated.ctp
I had the same problem and solved the problem with the following Classes in cakephp version 2.5.3 I have not checked whether my approach also works in older versions. First, I created a Helper and Component class which extends PaginationComponent and PaginationHelper and overwrote some Methods.
/app/Controller/Component/_PaginatorComponent.php
/app/View/Helper/_PaginatorHelper.php
And a View Element to use the Pagination quickly:
/app/View/Element/paging.ctp
You can call the paging-element in your view like this: (Documentation)
If you want use the new created paginator, you have to say cakephp to use your class instead of the normal paginator. In your controller, you set the PaginatorHelper and PaginatorComponent like this: (found here)
The usage inside your controller. The $paginate have to be grouped into the Modelgroups: (Documentation)
But I use it in the following context:
I hope I could help some people who do not want a javascript hack, but a real possibility to have several Paginations on one side.
At the moment you can only use 'paramType' => 'named'
In my opinion, the original code in PaginationComponent and PaginationHelper are horrible to read, extend and adapt.