ZF2儿童路线不起作用

时间:2014-03-06 12:28:11

标签: php routing zend-framework2

在阅读关于路由的数字清晰度后,我仍然无法使其工作。

当我这样做时,我可以去“/ portal”:

'portal' => array(
    'type' => 'Literal',
        'options' => array(
            'route' => '/portal',
            'defaults' => array(
                'controller' => 'Portal\Controller\Activities',
                'action' => 'index',
            ),
    ),
),

但是当我像这样添加child_routes时:

'portal' => array(
    'type' => 'Literal',
        'options' => array(
            'route' => '/portal',
            'defaults' => array(
                'controller' => 'Portal\Controller\Activities',
                'action' => 'index',
            ),
    ),
    'may_terminate' => true,
    'child_routes' => array(
        'default' => array(
            'type' => 'Segment',
            'options' => array(
                'route' => '[:controller[/:action]]',
                'constraints' => array(
                    'controller' => '[a-zA-Z][a-zA-Z0-9_-]*',
                    'action' => '[a-zA-Z][a-zA-Z0-9_-]*'
                ),
                'defaults' => array(
                    '__NAMESPACE__' => 'Portal\Controller',
                    'action' => 'index'
                ),
            ),
        ),
    ),
),

我仍然可以去“/ portal”但是当我去“/ portal / activities / index”(这是相同的)时,我得到“无法找到页面”。

希望有人可以提供帮助

提前致谢!

1 个答案:

答案 0 :(得分:0)

段定义不正确,缺少a /,因此完整的子路由当前是/ portal [:controller [/:action]]

将其更改为:

'portal' => array(
    'type' => 'Literal',
        'options' => array(
            'route' => '/portal',
            'defaults' => array(
                'controller' => 'Portal\Controller\Activities',
                'action' => 'index',
            ),
    ),
    'may_terminate' => true,
    'child_routes' => array(
        'default' => array(
            'type' => 'Segment',
            'options' => array(
                'route' => '/[:controller[/:action]]',
                'constraints' => array(
                    'controller' => '[a-zA-Z][a-zA-Z0-9_-]*',
                    'action' => '[a-zA-Z][a-zA-Z0-9_-]*'
                ),
                'defaults' => array(
                    '__NAMESPACE__' => 'Portal\Controller',
                    'action' => 'index'
                ),
            ),
        ),
    ),
),
相关问题