zend路由正则表达式问题

发布于 2024-12-17 13:32:45 字数 624 浏览 2 评论 0原文

我试图在 ini 文件中创建一条路由来匹配以下 URL,但没有成功。

/add-announce.html
/add-announce-books-53.html

我的路线是这样的:

routes.add_announcement.type = "Zend_Controller_Router_Route_Regex"
routes.add_announcement.route = "/add-announce(-[a-zA-Z_]+)?(-[\d]+)?.html"
routes.add_announcement.defaults.module = announcement
routes.add_announcement.defaults.controller = frontend
routes.add_announcement.defaults.action = add
routes.announcements.defaults.catName = null
routes.announcements.defaults.catId = null
routes.add_announcement.map.catName = 1
routes.add_announcement.map.catId = 2

I am trying to make a route in the ini file to match the following URLs, but I have been unsuccessful.

/add-announce.html
/add-announce-books-53.html

My route is this:

routes.add_announcement.type = "Zend_Controller_Router_Route_Regex"
routes.add_announcement.route = "/add-announce(-[a-zA-Z_]+)?(-[\d]+)?.html"
routes.add_announcement.defaults.module = announcement
routes.add_announcement.defaults.controller = frontend
routes.add_announcement.defaults.action = add
routes.announcements.defaults.catName = null
routes.announcements.defaults.catId = null
routes.add_announcement.map.catName = 1
routes.add_announcement.map.catId = 2

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

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

发布评论

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

评论(1

你是年少的欢喜 2024-12-24 13:32:45

也许因为你的匹配项开头有“-”?,你可以尝试使用:

routes.add_announcement.route = "add-announce(?:-([a-zA-Z_]+))?(?:-([\d]+))?.html"

编辑:我刚刚发现错误,你设置了错误的映射值:

routes.add_announcement.map.catName = 1
routes.add_announcement.map.catId = 2

相反你必须这样做:

routes.add_announcement.map.1 = "catName"
routes.add_announcement.map.2 = "catId"

还有routes.announcements。 defaults.catName 不应该是routes.add_announcement.defaults.catName 吗?

Maybe because your matches has '-' at the beginning?, Can you try with:

routes.add_announcement.route = "add-announce(?:-([a-zA-Z_]+))?(?:-([\d]+))?.html"

EDIT: I just found the error, you set the mapped values wrong:

routes.add_announcement.map.catName = 1
routes.add_announcement.map.catId = 2

instead you have to do it like this:

routes.add_announcement.map.1 = "catName"
routes.add_announcement.map.2 = "catId"

Also routes.announcements.defaults.catName shouldn't be routes.add_announcement.defaults.catName?

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