Zend Route XML 配置未按预期工作
下面是我的routes.xml,它被加载到我的Zend Framework 应用程序中。有两种路由,一种应该匹配 url /aanbod/tekoop/huis
,另一种应该匹配 /aanbod/200/gerenoveerde-woning
问题是这两个例子url 以详细操作结束,而第一个应该以索引操作结束。
谁能澄清这个路由设置有什么问题吗?
<routes>
<property_overview type="Zend_Controller_Router_Route">
<route>/aanbod/:category/:type</route>
<reqs category="(tekoop|tehuur)" />
<reqs type="[A-Za-z0-9]+" />
<defaults module="frontend" controller="property" action="index" />
</property_overview>
<property_detail type="Zend_Controller_Router_Route">
<route>/aanbod/:propertyid/:slug</route>
<reqs propertyid="[0-9]+" />
<reqs slug="(^\s)+" />
<defaults module="frontend" controller="property" action="detail" />
</property_detail>
</routes>
Below is my routes.xml which gets loaded in my Zend Framework app. There are two routes, one should match the url /aanbod/tekoop/huis
and the other should match /aanbod/200/gerenoveerde-woning
The problem is that both these example urls end up at the detail action while the first one should end up at the index action.
Can anyone clarify what's wrong with this routing setup?
<routes>
<property_overview type="Zend_Controller_Router_Route">
<route>/aanbod/:category/:type</route>
<reqs category="(tekoop|tehuur)" />
<reqs type="[A-Za-z0-9]+" />
<defaults module="frontend" controller="property" action="index" />
</property_overview>
<property_detail type="Zend_Controller_Router_Route">
<route>/aanbod/:propertyid/:slug</route>
<reqs propertyid="[0-9]+" />
<reqs slug="(^\s)+" />
<defaults module="frontend" controller="property" action="detail" />
</property_detail>
</routes>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
试试这个:
我改变了什么:
[^\s]+ 的意思是“除空格之外的任何字符一次或多次”,我想这就是你的意思。
Try this instead:
What I've changed:
[^\s]+
which means 'any character other than a space, one or more times', I think this is what you meant.我认为您不能使用
reqs
参数来帮助识别Zend_Controller_Router_Route
的路由。在您的情况下,您的路线是相同的,并且由于路线堆栈是后进先出的,因此“详细”路线优先。也许尝试使用
Zend_Controller_Router_Route_Regex
相反。我很难找到正则表达式路由器的配置方法,但在代码中它看起来像
I don't think you can use the
reqs
parameter to help identify the route forZend_Controller_Router_Route
. In your case, your routes are identical and as the route stack is LIFO, the "detail" one takes precedence.Perhaps try using
Zend_Controller_Router_Route_Regex
instead.I'm having a hard time finding the configuration method for the regex router but in code it would look something like