Zendframework 路由问题
我一直在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
search/:page/:col/:sort/:limit/
与www.mywebsite.com/search/action/2
不匹配。您的路线正在寻找search/
,后跟代表页码的数字(\d
);但是,您请求search/
后跟字符串action
。我建议在您的路线中添加另一个参数:search/:action/:page/:col/:sort/:limit
,默认action
为index.
请求默认操作的首页保持不变(
搜索
)。请求默认路由的第 2 页现在为search/index/2/
,但您现在可以指定不同的操作 (search/action/2
)。search/:page/:col/:sort/:limit/
doesn't matchwww.mywebsite.com/search/action/2
. Your route is looking forsearch/
followed by a digit (\d
) that represents the page number; however, you're requestingsearch/
followed by the stringaction
. I would suggest adding another parameter to your route:search/:action/:page/:col/:sort/:limit
, defaultingaction
toindex
.Requesting the first page of the default action stays the same (
search
). Requesting page 2 of the default route will now besearch/index/2/
, but you can now specify a different action (search/action/2
).