Zf2 子路由在有一个子路由时不起作用。

Zf2 child route not working when it has one more child.

我正在使用 zf2 并且我定义了这样的子路由。

'routes' => array(
            'test' => array(
                'type'    => 'Literal',
                'options' => array(
                    'route'    => '/test',
                    'defaults' => array(
                        '__NAMESPACE__' => 'Test\Controller',
                        'controller'    => 'Test',
                        'action'        => 'index',
                    ),
                ),
                'may_terminate' => true,
                'child_routes' => array(
                    'testABC' => array(
                            'type' => 'Literal',
                            'options' => array(
                                    'route'    => '/abc',
                                    'defaults' => array(
                                            'action'     => 'abc',
                                    ),
                            ),
                            'child_routes' => array(
                                    'testABCDEF' => array(
                                            'type' => 'Segment',
                                            'options' => array(
                                                    'route'    => '/def/:id',
                                                    'defaults' => array(
                                                            'action'     => 'def',
                                                    ),
                                            ),
                                    ),
                                    'testABCXYZ' => array(
                                            'type' => 'Segment',
                                            'options' => array(
                                                    'route'    => '/xyz/:id',
                                                    'defaults' => array(
                                                            'action'     => 'xyz',
                                                    ),
                                            ),
                                    ),
                             ),
                    ),
                ),
            ),
        ),

在这只有一条路由不行,不知道为什么?

问题是因为您的testABC路由缺少may_terminate选项。

如果它没有 children,它会隐式终止,但是因为它有 children,你必须明确地通知路由器这种可能性(就像你对它的 parent test路线。)

'testABC' => array(
    'type' => 'Literal',
    'options' => array(
        'route'    => '/abc',
        'defaults' => array(
            'action'     => 'abc',
        ),
    ),
    'may_terminate' => true, // inform the router
    'child_routes' => (
         // ...
    ),
),