Create custom CakePHP Pagination Route
I am trying to use Ajax pagination in CakePHP and have read you can pass the variables along in the URL however I cannot seem to set the route. When I click on next I get an error about the category not existing (because of a custom validation method I created) because the route isn't being followed.
I would like the $paginator->next()
and $paginator->prev()
to follow this scheme of routes
http://mysite.com/computers/page:2
or http://mysite.com/computers/mac/page:2
. However no matter what I set the pagination URL to it always ends up becoming http://mysite.com/Products/index/page:2
. I have tried setting the URL in the $paginator->options()
and in the $paginator->next()
and $paginator->prev()
however it is not working. Any ideas on how to make cakephp paginator follow my custom routes?
Edit:
Here is my $paginator code that is in the view.
$paginator->options(array(
'update' => '#products',
'url' => array('controller'=>'Products','action'=>'index','pass'=>$this->params['pass']),
'evalScripts' => true,
'before' => $this->Js->get('#busy-indicator')->effect('fadeIn', array('buffer' => false)),
'complete' => $this->Js->get('#busy-indicator')->effect('fadeOut'开发者_运维技巧, array('buffer' => false)),
));
echo $paginator->prev("Prev",$this->passedArgs);
echo $paginator->numbers(array('separator'=>' '));
echo $paginator->next("Next",$this->passedArgs);
I figured it out. I see someone has favorited this so I will show my resolution in hopes that it saves them a few days of frustration trying to find a fix.
In my index.ctp I set the $paginator->options path to my url I needed.
$paginator->options(array(
'update' => '#products',
'url' => array('path'=>$this->params['path']),
'evalScripts' => true,
'before' => $this->Js->get('#busy-indicator')->effect('fadeIn', array('buffer' => false)),
'complete' => $this->Js->get('#busy-indicator')->effect('fadeOut', array('buffer' => false)),
));
Edit: I just found out this only works if you don't add anything else to the url field... :-(
Edit 2: I ended up having to do this in my view where the $pagination is created.
$paginator->options(array(
'update' => '#products',
'url' => '/'.$this->here,
//'evalScripts' => true,
'before' => $this->Js->get('.clothing')->effect('fadeOut', array('speed' => 'slow')),
'complete' => $this->Js->get('.clothing')->effect('fadeIn', array('speed' => 'slow')),
));
echo str_replace('/Products/index','',$paginator->prev("Prev "));
echo str_replace('/Products/index','',$paginator->numbers(array('separator'=>' - ')));
echo str_replace('/Products/index','',$paginator->next(" Next"));
If you set paginator options it should do the trick. Try this:
$options = array('update'=>'results','url'=> array('controller' => 'companies', 'action' => 'dashboard', 'admin' => true));
$paginator->options($options);
That works perfectly for me everywhere.
FYI, I use the 'update' param with jQuery to update various areas.
精彩评论