使用子项时,ZF2 Segment Route与父项的约束不匹配

时间:2015-05-19 17:41:42

标签: regex routing routes zend-framework2 zend-route

我创建了以下路线:

'relatorios' => array(
    'type'    => 'Zend\Mvc\Router\Http\Segment',
    'options' => array(
        'route'       => '/relatorios/:tipo',
        'defaults'    => array(
            'controller' => 'Relatorios',
            'action'     => 'index',
            'tipo'       => 'normais',
        ),
        'constraints' => array('tipo' => '(normais|administrativos)$',
    ),
    'may_terminate' => true,
    'child_routes'  => array(
        'view' => array(
            'type'    => 'Zend\Mvc\Router\Http\Segment',
            'options' => array(
                'route'       => '/view/:id_relatorio',
                'defaults'    => array('action'       => 'view'),
                'constraints' => array('id_relatorio' => '[0-9]+'),
            ),
        ),
    ),
);

这应该符合以下路线:
/ relatorios / normais //matches
/ relatorios / administrativos //matches
/ relatorios / normais / view / 1 //doesn't match
/ relatorios / administrativos / view / 1 //doesn't match

所以基本上:tipo参数必须是normaisadministrativos,并且有一个孩子/view/any_digits
当调用父路由时,它匹配,当调用子视图时,由于我的tipo约束,它不匹配。那是为什么?

1 个答案:

答案 0 :(得分:2)

根据我的评论,约束上的$表示字符串'的结尾。 (在这种情况下是URL路径),所以它不应该在那里。