我正在使用zf2,并且我已经定义了这样的子路由。
'routes' => array(
'test' => array(
'type' => 'Literal',
'options' => array(
'route' => '/test',
'defaults' => array(
'__NAMESPACE__' => 'TestController',
'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',
),
),
),
),
),
),
),
),
在这只有一条路线不起作用,我不知道为什么?
- 本地主机/测试 工作
- 本地主机/测试/ABC不工作
- localhost/test/abc/def/1工作
- localhost/test/abc/xyz/1工作
导致此问题的原因是您的testABC
路由缺少may_terminate
选项。
如果它没有子路由,它将隐式终止,但由于它有子路由,因此必须明确通知路由器这种可能性(就像处理其父路由test
一样(。
'testABC' => array(
'type' => 'Literal',
'options' => array(
'route' => '/abc',
'defaults' => array(
'action' => 'abc',
),
),
'may_terminate' => true, // inform the router
'child_routes' => (
// ...
),
),