Zend 路由正则表达式问题
我正在开发一个多语言 Zend 项目。我正在创建事件,所以我想使用这样的结构:
- domain.com/event/2010/ => 2010 年活动
- domain.com/event/2010/11/ => 2010 年 11 月活动
- domain.com/event/2010/11/23/ => 2010 年 11 月 23 日的活动
为此,我创建了以下路线:
$router->addRoute('event', new Zend_Controller_Router_Route_Regex('event/(\d+)(/(\d+)(/(\d+))?)?', array(
'module' => 'public',
'controller' => 'event',
'action' => 'show'
)));
$router->addRoute('eventLang', new Zend_Controller_Router_Route_Regex(':language/event/(\d+)(/(\d+)(/(\d+))?)?', array(
'language'=>'en'
'module' => 'public',
'controller' => 'event',
'action' => 'show'
)));
第一条非常完美。第二个显示错误,例如“操作 2010 不存在”。这里有什么问题???
I'm developing a multilanguage Zend project. I am creating events so I wanna use a structure like this:
- domain.com/event/2010/ => Events on year 2010
- domain.com/event/2010/11/ => Events on november 2010
- domain.com/event/2010/11/23/ => Events on november, 23th 2010
For this pourpuse I created the following routes:
$router->addRoute('event', new Zend_Controller_Router_Route_Regex('event/(\d+)(/(\d+)(/(\d+))?)?', array(
'module' => 'public',
'controller' => 'event',
'action' => 'show'
)));
$router->addRoute('eventLang', new Zend_Controller_Router_Route_Regex(':language/event/(\d+)(/(\d+)(/(\d+))?)?', array(
'language'=>'en'
'module' => 'public',
'controller' => 'event',
'action' => 'show'
)));
The first one works perfect. the second one display an error like "action 2010 does not exists". What is the problem here???
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您不能在 Zend_Controller_Router_Route_Regex 中使用变量(在您的情况下是
:language
)。你应该用下面的方式重写你的正则表达式:You can't use variables (
:language
in your case) in Zend_Controller_Router_Route_Regex. You should rewrite your regexp in next way: