因此,我尝试使用分页器和自定义路由对索引页面上的项目进行分页。这一切都是通过索引操作完成的,但索引操作可以显示按最新、投票、活跃或视图排序的项目。现在,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
我怎样才能让它跟随路由器并给我我想要的东西?请记住,这一切都来自相同的控制器操作,我基本上正在尝试路由分页的排序参数。
So I'm trying to page items on my index page using the paginator and custom routes. It's all through the index action, but the index action can show items sorted by newest, votes, active or views. Right now, the URL looks like this:
items/index/sort:created/direction:desc
And if you aren't on page one, it looks like this:
items/index/sort:created/direction:desc/page:2
I'd like to use the router to have it look like this:
newest/
I can get that far with this route:
Router::connect(
'/newest/*',
array('controller'=>'items', 'action'=>'index', 'sort'=>'created', 'direction'=>'desc')
);
However, the pager links don't follow the route. As soon as you click next page, you're back to:
items/index/sort:created/direction:desc/page:2
How can I make this follow the router and give me what I want? Keep in mind, it's all from the same controller action, I'm trying to route the sort parameters of pagination basically.
发布评论
评论(2)
对我来说,你的代码正在工作(我已经测试了你的示例)。您是否使用分页器助手做了一些不寻常的事情?
这是我的路线:
这是我按年龄列排序时看到的网址:
最旧的:
它适用于寻呼机中的所有链接(第一个、上一个、1、2、3、下一个、最后一个)。
For me your code is working (I've tested your example). Have you done something unusual with the paginator helper?
Here is my Routes:
And here are the urls which I've seen when I sort by age column:
And oldest:
And it's working with all links in the pager (first, prev, 1,2,3 next, last).
我认为你想包含传递的参数。像这样的东西,
也在这里检查一下, http://book.cakephp.org/view /46/Routes-Configuration
否则,我将扩展 HTML Helper 以创建我自己的链接方法,该方法从 url 读取参数并相应地创建链接。然后你可以从你自己的助手管理你自己的链接:)
不要忘记你需要检查索引操作来处理这个问题。就我个人而言,我更倾向于在控制器中为每一个创建一个操作。
You want to include the passed args I think. Something like this,
Have a check here also, http://book.cakephp.org/view/46/Routes-Configuration
Otherwise I would extend the HTML Helper to create my own link method which read in the parameters from the url and created a link accordingly. Then you could manage your own links from your own helper :)
Don't forget that you need to have checks in the index action to deal with this. Personally I would be far more inclined to create an action in the controller for each of these.