所以我正在尝试使用分页器和自定义路由在我的索引页面上分页。这完全是通过索引操作,但索引操作可以显示按最新,投票,活动或视图排序的项目。现在,URL看起来像这样:
items/index/sort:created/direction:desc
如果你不在第一页,它看起来像这样:
items/index/sort:created/direction:desc/page:2
我想使用路由器看起来像这样:
newest/
我可以用这条路走得那么远:
Router::connect(
'/newest/*',
array('controller'=>'items', 'action'=>'index', 'sort'=>'created', 'direction'=>'desc')
);
但是,寻呼机链接不遵循该路线。点击下一页后,您将返回:
items/index/sort:created/direction:desc/page:2
如何让它跟随路由器并给我我想要的东西?请记住,这一切都来自同一个控制器动作,我试图基本上分配分页的排序参数。
答案 0 :(得分:3)
对我来说,你的代码正在运行(我已经测试了你的例子)。你有没有使用paginator helper做一些不寻常的事情?
这是我的路线:
Router::connect('/newest/*',array('controller'=>'tests', 'action'=>'index', 'sort'=>'age', 'direction'=>'desc'));
Router::connect('/oldest/*',array('controller'=>'tests', 'action'=>'index', 'sort'=>'age', 'direction'=>'asc'));
以下是按年龄栏排序时我看到的网址:
http://localhost/cakephp/1.3.0/newest/page:1
http://localhost/cakephp/1.3.0/newest/page:2
http://localhost/cakephp/1.3.0/newest/page:3
最老的:
http://localhost/cakephp/1.3.0/oldest/page:1
http://localhost/cakephp/1.3.0/oldest/page:2
http://localhost/cakephp/1.3.0/oldest/page:3
它正在处理寻呼机中的所有链接(首先,上一个,1,2,3下一个,最后一个)。
答案 1 :(得分:0)
你想要包含我认为传递的args。像这样的东西,
$this->params = $this->passedArgs();
也可以在这里查看http://book.cakephp.org/view/46/Routes-Configuration
否则我会扩展HTML Helper以创建我自己的链接方法,该方法从url中读取参数并相应地创建链接。然后,您可以从自己的帮助者管理自己的链接:)
不要忘记您需要在索引操作中进行检查才能解决此问题。就个人而言,我更倾向于在控制器中为每一个创建一个动作。
function newest(){
}
function votes(){
}
function active(){
}
//etc