创建自定义CakePHP的分页路线 [英] Create custom CakePHP Pagination Route
问题描述
我想使用Ajax分页CakePHP中,并已阅读,你可以通过变量沿着URL,但是我似乎无法设置路由。当我点击下一步我得到的类别不存在(因为我创建了一个自定义的验证方法),因为路线不被跟踪的误差。
我想 $ paginator->接下来()
和 $ paginator-> preV()
按照路线这个方案
http://mysite.com/computers/page:2
或 http://mysite.com/computers/mac/page:2
。但是不管我设置分页网址它总是最终成为 http://mysite.com/Products/index/page:2
。我已经试过设置在 $ paginator-&GT的URL;选项()
和 $ paginator->接下来()
和 $ paginator-> preV()
但它不工作。如何使CakePHP的分页程序按照我的定制路由任何想法?
编辑:
下面是我的$分页程序code,它是在视图中。
$ paginator->选项(阵列(
更新=> #products,
'URL'=>阵列(控制器=>'产品','行动'=>'指数','通'=> $这个 - > PARAMS ['传球']),
evalScripts'=>真正,
之前'=> $这个 - > Js->获得('#忙指标) - >的效果(淡入,阵列('缓冲'=> FALSE)),
完整的=> $这个 - > Js->获得('#忙指标) - >的效果('淡出',阵列('缓冲'=> FALSE)),
));
回声$ paginator-> $ P $光伏(preV,$这 - > passedArgs);
回声$ paginator->数字(阵列('分离'=>''));
回声$ paginator->接下来(下一步,$这 - > passedArgs);
我想它了。我看到有人收藏这个,所以我会告诉我的,希望解决它节省了他们的无奈几天试图寻找一个解决方法。
在我index.ctp我设置了$ paginator->选择路径,我的网址我需要的。
$ paginator->选项(阵列(
更新=> #products,
'URL'=>阵列('路径'=> $这个 - > PARAMS ['路径']),
evalScripts'=>真正,
之前'=> $这个 - > Js->获得('#忙指标) - >的效果(淡入,阵列('缓冲'=> FALSE)),
完整的=> $这个 - > Js->获得('#忙指标) - >的效果('淡出',阵列('缓冲'=> FALSE)),
));
编辑: 我才发现这只是工作,如果你没有任何其他的URL字段中添加...: - (
编辑2: 我最后不得不这样做我在这里创建了$分页视图。
$ paginator->选项(阵列(
更新=> #products,
'URL'=> /'.$this->here,
//'evalScripts'=>真正,
之前'=> $这个 - > Js->获得(服装。') - >的效果('淡出',阵列('速度'=>慢)),
完整的=> $这个 - > Js->获得(服装。') - >的效果(淡入,阵列('速度'=>慢)),
));
回声str_replace函数('/产品/指数','',$ paginator-> $ P $光伏(preV));
回声str_replace函数('/产品/指数','',$ paginator->数字(阵列('分离'=>' - ')));
回声str_replace函数('/产品/指数','',$ paginator->接下来(下一步));
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"));
这篇关于创建自定义CakePHP的分页路线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!