我从未擅长正则表达。我正在尝试使用它们来构建一个简单的站点。我构建一个像/some-course/some-vtm-1
一样好的URL,但是当它试图查找定义的控制器时,它就失败了。这是我定义的路线:
chapter' => array(
'type' => 'Zend_Controller_Router_Route_Regex',
'route' => '/:course/:vtm\-(\d+)',
'defaults' => array(
'module' => 'learn',
'controller' => 'chapter',
'action' => 'index'
),
'map' => array(
1 => 'course',
2 => 'vtm',
3 => 'id'
),
'reverse' => '%s/%s-%d/'
),
当我点击/some-course/some-vtm-1
之类的链接时,如何更正此正则表达式以便找到正确的模块/控制器/操作
答案 0 :(得分:3)
你的问题是你试图混合Zend_Controller_Router_Route
(在:
开头的路线中的命名变量)和Zend_Controller_Router_Route_Regex
(在路线中括起来的正则表达式模式)的语法。你想放弃前者并只使用regexp语法,留下这样的东西:
array(
'type' => 'Zend_Controller_Router_Route_Regex',
'route' => '([\w]+)/(vtm)-([\d]+)',
'defaults' => array(
'module' => 'learn',
'controller' => 'chapter',
'action' => 'index'
),
'map' => array(
1 => 'course',
2 => 'vtm',
3 => 'id'
),
'reverse' => '%s/%s-%d'
),