3

我在设置 child_routes 时遇到了一些麻烦。除非我将它们分开,否则它们不起作用,尽管最终结果应该是相同的!:

这就是我想要实现的目标:

'router' => array(
        'routes' => array(
            'app' => array(
                'type' => 'Zend\Mvc\Router\Http\Segment',
                'options' => array(
                    'route' => '[/:info]/app',
                    'defaults' => array(
                        '__NAMESPACE__' => 'X\App',
                        'controller' => 'Index',
                        'action' => 'index',
                    ),
                    'may_terminate' => true,
                    'child_routes' => array(
                        'example' => array(
                            'type' => 'Zend\Mvc\Router\Http\Segment',
                            'options' => array(
                                'route' => '/example[:/data]',
                                'defaults' => array(
                                    'action' => 'example',
                                ),
                            ),
                        ),
                    ),
                ),
            ),
        ),

但它只能这样工作:

'router' => array(
        'routes' => array(
            'app' => array(
                'type' => 'Zend\Mvc\Router\Http\Segment',
                'options' => array(
                    'route' => '[/:info]/app',
                    'defaults' => array(
                        '__NAMESPACE__' => 'X\App',
                        'controller' => 'Index',
                        'action' => 'index',
                    ),                    
                ),
            ),
            'app.example' => array(
                'type' => 'Zend\Mvc\Router\Http\Segment',
                'options' => array(
                    'route' => '[/:info]/app/example[/:data]',
                    'defaults' => array(
                        '__NAMESPACE__' => 'X\App',
                        'controller' => 'Index',
                        'action' => 'example',
                    ),
                ),
            ),
        ),

..任何人都知道我可能做错了什么..?

4

2 回答 2

6

您的子路线在错误的位置,它们不属于options数组,也不属于may_terminate key,试试这个......

'router' => array(
    'routes' => array(
        'app' => array(
            'type' => 'Zend\Mvc\Router\Http\Segment',
            'options' => array(
                'route' => '[/:info]/app',
                'defaults' => array(
                    '__NAMESPACE__' => 'X\App',
                    'controller' => 'Index',
                    'action' => 'index',
                ),
            ),
            'may_terminate' => true,
            'child_routes' => array(
                'example' => array(
                    'type' => 'Zend\Mvc\Router\Http\Segment',
                    'options' => array(
                        'route' => '/example[:/data]',
                        'defaults' => array(
                            'action' => 'example',
                        ),
                    ),
                ),
            ),
        ),
    ),
),
于 2013-03-06T15:07:34.623 回答
1

你的语法错误

在第一个示例中,您的选项数组中有 chil_routes 定义,它需要与选项数组处于同一级别:

'router' => array(
    'routes' => array(
        'app' => array(
            'type' => 'Zend\Mvc\Router\Http\Segment',
            'options' => array(
                'route' => '[/:info]/app',
                'defaults' => array(
                    '__NAMESPACE__' => 'X\App',
                    'controller' => 'Index',
                    'action' => 'index',
                ),
            ),
            'may_terminate' => true,
            'child_routes' => array(
                'example' => array(
                    'type' => 'Zend\Mvc\Router\Http\Segment',
                    'options' => array(
                        'route' => '/example[:/data]',
                        'defaults' => array(
                            'action' => 'example',
                        ),
                    ),
                ),
            ),
        ),
    ),
于 2013-03-06T15:09:21.893 回答