Zendframework 路由问题

发布于 2024-08-15 04:53:49 字数 991 浏览 8 评论 0原文

我一直在 application.ini 文件中设置我的路线,该文件适用于我设置的所有路线。问题是当该控制器中有多个操作并且我尝试在其他操作中使用路由时。

例如,我在 application.ini 中创建了以下内容用于分页和列排序

resources.router.routes.search.route = "search/:page/:col/:sort/:limit/"
resources.router.routes.search.defaults.controller = search
resources.router.routes.search.defaults.page = 1
resources.router.routes.search.defaults.col = time
resources.router.routes.search.defaults.sort = default
resources.router.routes.search.defaults.limit = 50
resources.router.routes.search.reqs.page = \d+
resources.router.routes.search.reqs.col = \w+
resources.router.routes.search.reqs.sort = \w+
resources.router.routes.search.reqs.limit = \d+

当我处于该页面的默认操作(例如“

www.mywebsite.com/search/2/

将显示结果的第二页”)时,上述内容有效。但如果我在另一个操作上尝试相同的操作,

www.mywebsite.com/search/action/2

它只会显示一个空白页面。我尝试在 ini 中创建自己的设置,但没有成功。我以前遇到过这个问题,但通常只是放弃并将事物分离到不同的控制器中,但我宁愿采取不同的操作。

任何帮助将不胜感激。

马特

I have been setting my routes in my application.ini file which works for all the ones i have setup. The problem is when there are multiple actions within that controller and i try to use the routes in other actions.

For instance i have created the following in my application.ini for paging and column sorting

resources.router.routes.search.route = "search/:page/:col/:sort/:limit/"
resources.router.routes.search.defaults.controller = search
resources.router.routes.search.defaults.page = 1
resources.router.routes.search.defaults.col = time
resources.router.routes.search.defaults.sort = default
resources.router.routes.search.defaults.limit = 50
resources.router.routes.search.reqs.page = \d+
resources.router.routes.search.reqs.col = \w+
resources.router.routes.search.reqs.sort = \w+
resources.router.routes.search.reqs.limit = \d+

The above works when I'm on the default action of that page like

www.mywebsite.com/search/2/

Would bring up the second page of the results. But if I try the same on another action,

www.mywebsite.com/search/action/2

It just shows a blank page. I tried creating its own settings in the ini and that did not work. I've run across this problem before but usually just gave up and separated things into different controllers but i would rather have different actions.

Any help would be much appreciated.

Matt

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

白芷 2024-08-22 04:53:49

search/:page/:col/:sort/:limit/www.mywebsite.com/search/action/2 不匹配。您的路线正在寻找search/,后跟代表页码的数字(\d);但是,您请求 search/ 后跟字符串 action。我建议在您的路线中添加另一个参数:search/:action/:page/:col/:sort/:limit,默认actionindex.

请求默认操作的首页保持不变(搜索)。请求默认路由的第 2 页现在为 search/index/2/,但您现在可以指定不同的操作 (search/action/2)。

search/:page/:col/:sort/:limit/ doesn't match www.mywebsite.com/search/action/2. Your route is looking for search/ followed by a digit (\d) that represents the page number; however, you're requesting search/ followed by the string action. I would suggest adding another parameter to your route: search/:action/:page/:col/:sort/:limit, defaulting action to index.

Requesting the first page of the default action stays the same (search). Requesting page 2 of the default route will now be search/index/2/, but you can now specify a different action (search/action/2).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文