' __ NAMESPACE __'在路由配置永远不会工作,并在Zend Framework 2(zf2)中的child_routes出错

时间:2014-04-12 02:55:52

标签: php zend-framework2

return array(
    'controllers' => array(
        'invokables' => array(
            'Manager\Controller\Index' => 'Manager\Controller\IndexController',
            'Manager\Controller\Blog\Blog'  => 'Manager\Controller\Blog\BlogController',

        ),
    ),
    'router' => array(
        'routes' => array(
            'manager' => array(
                'type' => 'Hostname',
                'options' => array(
                    'route' => 'management.yfco.com',
                    'defaults' => array(
                        '__NAMESPACE__' => 'Manager\Controller',
                        'controller' => 'Index',
                        'action' => 'index',
                    )
                ),
                'may_terminate' => TRUE,
                'child_routes' => array(
                    'blog' => array(
                        'type' => 'Segment',
                        'options' => array(
                            'route' => '/blog[/:controller[/:action[/:id]]]',
                            'defaults' => array(
                                '__NAMESPACE__' => 'Manager\Controller\Blog',
                                'controller' => 'Blog',
                                'action' => 'index'
                            ),
                        ),
                    ),
                ),
            ),
        )
    ),
);

以上是我在module.config.php中的配置。密钥__NAMESPACE__永远不会起作用,Zf2告诉“解析为无效的控制器类或别名:博客”。

另一个问题是,当我没有设置child_routes时,routeMatch可以找到正确的Controller,即“Manager \ Controller \ Index”,但是当我添加上下文时,routeMatch会在其他模块中找到其他Controller (\ Application \ Controller \ IndexController的索引操作)。

如何解决问题。我无法在zf网站上获得更多信息。

1 个答案:

答案 0 :(得分:0)

您不应该需要'__NAMESPACE__' => 'Manager\Controller\Blog',代码行。

试试

'may_terminate' => TRUE,
'child_routes' => array(
    'blog' => array(
        'type' => 'Segment',
        'options' => array(
            'route' => '/blog[/:controller[/:action[/:id]]]',
            'defaults' => array(
                'controller' => 'Blog',
                'action' => 'index'
            ),
        ),
    ),
),