zend-framework2 - ZF2 子路由问题

标签 zend-framework2 zend-route

我在设置 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',
                    ),
                ),
            ),
        ),

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

最佳答案

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

'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',
                        ),
                    ),
                ),
            ),
        ),
    ),
),

关于zend-framework2 - ZF2 子路由问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15250737/

相关文章:

mysql - ZF2 查询日期时间列的 DATE() WHERE 子句

zend-framework2 - 动态更改 zend 框架 2 中的默认路由参数?

php - Magento 模块的 URL 重写

php - 禅德 : The url assembled by the URL view helper is incorrect

php - Zend Framework 2 中的数据库日志记录 : wrong "extra" column name

mysql - zend_db 查询到 Doctrine 2 querybuilder 的转换

php - Zf2 Db Sessions 插入但不更新数据库中的 session

php - Zend Framework 2 中的路由

php - 包含架构、域和端口的完整 url

php - 404 请求的 URL 无法被路由匹配