编程语言
首页 > 编程语言> > CakePHP:如何路由分页的排序参数?

CakePHP:如何路由分页的排序参数?

作者:互联网

因此,我尝试使用分页器和自定义路线对索引页面上的项目进行分页.这全部通过index动作完成,但是index动作可以显示按最新,投票,活动或视图排序的项目.现在,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

如何使它跟随路由器并给我我想要的东西?请记住,所有这些都是来自同一控制器动作,我正在尝试基本路由分页的排序参数.

解决方法:

对我来说,您的代码正在运行(我已经测试了您的示例).您是否使用分页器助手做了一些不寻常的事情?

这是我的路线:

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下一个,最后一个).

标签:cakephp,pagination,php
来源: https://codeday.me/bug/20191209/2095712.html