我尝试在zend框架2中验证路由。
示例:
我尝试了这段代码,但收到了404错误:
'overview' => array(
'type' => 'segment',
'options' => array(
'route' => '/foo/overview/:nr',
'constraints' => array('nr' => '^[0-9]{1,4}-[0-9]{4}$',),
'defaults' => array(
'controller' => 'Foo\Controller\Foo',
'action' => 'overview',
),
),
),
感谢
答案 0 :(得分:2)
使用[0-9]{1,4}-[0-9]{4}
作为约束值就足够了,因为框架会自动添加起始^
和结束$
(请检查match
函数Zend\Mvc\Router\Http\Segment
类。)