如何在CakePHP中重定向后保留页码? [英] How do you maintain page number after redirect in CakePHP?

查看:264
本文介绍了如何在CakePHP中重定向后保留页码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个索引视图列出项目,它是一个长列表,所以我使用Paginator限制项目到50到一个视图。

I have an index view that lists items, and it's a long list so I use Paginator to limit items to 50-to-a-view.

每个项目有一个编辑链接,转到具有输入/验证等的编辑视图。当提交表单时,我将使用重定向到索引视图。

Each item has an "edit" link that goes to an edit view with inputs/validations/etc. When that form is submitted, I redirect the use back to the index view.

到目前为止很好,但这里是rub:

So far so good, but here's the rub:

如果用户在索引的第N页,并且他们单击编辑和编辑项目,我希望它们被重定向回索引的第N页。如果我知道页码,我可以坚持/ page:N到结束的URL,但我不知道如何我可以得到页码。 (N可以是任何页码,但特别是> = 2)

If a user is on page N of the index and they click edit and edit an item, I want them to be redirected back to page N of the index. If I knew the page number, I could just stick "/page:N" on to end of the URL, but I have no idea how I can get the page number. (N could be any page number, but especially >=2)

任何想法都会感激。

推荐答案

页码应该是列表视图中$ params var的一部分。只需将其粘到编辑链接的末尾,并从那里处理它。在编辑页面上,您将需要一种方法来接收可选的页码,在提交任何表单时存储它,并返回到具有相同页码的列表。

The page number should be part of the $params var in the list view. Just tack it onto the end of the edit link and handle it from there. On the edit page you will need a way to take in the optional page number, store it during any form submission, and forward back to the list with the same page number.

这篇关于如何在CakePHP中重定向后保留页码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆