我在设置 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/