CakePHP:如何路由分页';s排序参数?

CakePHP:如何路由分页';s排序参数?,php,cakephp,pagination,Php,Cakephp,Pagination,因此,我尝试使用分页器和自定义路由在索引页上分页项目。这都是通过索引操作完成的,但是索引操作可以显示按最新、投票、活动或视图排序的项目。现在,URL如下所示: items/index/sort:created/direction:desc items/index/sort:created/direction:desc/page:2 newest/ 如果你不在第一页,它看起来是这样的: items/index/sort:created/direction:desc items/index/

因此,我尝试使用分页器和自定义路由在索引页上分页项目。这都是通过索引操作完成的,但是索引操作可以显示按最新、投票、活动或视图排序的项目。现在,URL如下所示:

items/index/sort:created/direction:desc
items/index/sort:created/direction:desc/page:2
newest/
如果你不在第一页,它看起来是这样的:

items/index/sort:created/direction:desc
items/index/sort:created/direction:desc/page:2
newest/
我想使用路由器使其看起来像这样:

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

我怎样才能让它跟随路由器,给我我想要的?请记住,这都是来自同一个控制器操作,我尝试基本上路由分页的排序参数。

我认为您希望包括传递的参数。像这样的,

$this->params = $this->passedArgs();
在这里也检查一下

否则,我将扩展HTML助手来创建我自己的链接方法,该方法从url读取参数并相应地创建链接。然后您可以从自己的助手管理自己的链接:)

不要忘记,您需要在索引操作中进行检查以处理此问题。就我个人而言,我更倾向于在控制器中为每一项创建操作

function newest(){

}
function votes(){

}
function active(){

}

//etc

对我来说,您的代码正在运行(我已经测试了您的示例)。您是否对paginator助手做了一些不寻常的事情

以下是我的路线:

Router::connect('/newest/*',array('controller'=>'tests', 'action'=>'index', 'sort'=>'age', 'direction'=>'desc'));
Router::connect('/oldest/*',array('controller'=>'tests', 'action'=>'index', 'sort'=>'age', 'direction'=>'asc'));
以下是我在按年龄列排序时看到的URL:

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、下一、最后)。

我相信Daniel是在要求其他东西:Cake非常聪明,如果你创建一个指向控制器/操作的链接,并且该链接具有匹配的路由条目,Cake会用路由速记替换url。但这似乎不适用于分页url-s。如果您为这些url-s创建单独的操作,您只需复制代码。我使用的是cakephp 1.3.4,是否可能跨版本破坏了此功能?不,我已经用1.3.0进行了测试,但是我用1.3.4和1.3.5进行了测试,在所有情况下,它们都按预期工作。奇怪。我想知道我的实现是否有问题。这不是我第一次遇到别人无法复制的东西。好吧,我更新到1.3.6,它修复了它。我不知道之前发生了什么。也许我把事情搞砸了。