Cakephp pagination and custom named arguments handling
Let’s have a look at the scenario first.
I have a “contacts” controller, a “display” action in it(controller) and a view “display.ctp” to show results. As normal my “display” action lists all the contacts by calling $this->set(‘contacts’, $this->paginate(‘Contact’)) inside the controller action “display”. The view works normal.
Now, i want to pass a named argument to controller action. Say “category:friends” so that i could filter results further. In this case the calling url looks like “http://mysite.com/contacts/display/category:friends”. In general, when i call it, results span through multiple pages normally, but the html urls of “next”, “previous”, “1″, “2″, “3″..etc. no more have passed argument i.e. “category:friends” in it(the urls), rather it looks like http://mysite.com/contacts/display/page:1 as before. So what do i need to do so that pagination urls contain “category:friends” along with other pagination arguments like “page:1″, “sort:fieldname”, “direction:asc” etc. etc..? In other words i want pagination urls to look like http://mysite.com/contacts/display/page:1/category:friends and so on.
The answer is simple. Just add the following code anywhere in your view, but only before a call to paginator function:
$paginator->options(array('url' => $this->passedArgs));
In my case i use it like this:
$paginator->options(array('url' => $this->passedArgs));
echo $paginator->prev('< ');
echo $paginator->numbers(array('separator'=>' '));
echo $paginator->next('>');
Possibly Related posts:
- Passed arguments routing and custom ajax pagination url in cakephp
While working in my recent “charity project” i had to list all charities found in a particular region or state. I created a regions_controller and... - Error handling in cakephp
Error handling in CakePHP is pretty simple and straight forward. While developing in CakePHP with debug value set to > 0 (Configure::write(‘debug’, 1); in app/config/core.php)... - How to apply search filters in cakephp ajax pagination
Sometimes we need to filter records via custom query while using ajax pagination in a cakephp application. An easy way to achieve this is to... - An alternate to paginator counter showing page in cakephp
An ordinary yet useful piece of hack to the way the cakephp pagination’s pages “showing page” parameter is displayed. As default, we are used to... - Use of custom displayField paramater in CakePHP
The $this->displayField is used to define custom display field while doing ‘list’ or scaffolding in CakePHP. It can be specified either in Model class or...
If you enjoyed this post, please consider to leave a comment or subscribe to the feed and get future articles delivered to your feed reader.





