我在Zend Framework 2中使用ZfcUser模块 在Controller文件夹中 控制器
--UserController.php
--EmployerController.php
在module.config.php中,我使用route
进行配置'router' => array(
'routes' => array(
'zfcuser' => array(
'type' => 'Literal',
'priority' => 1000,
'options' => array(
'route' => '/user',
'defaults' => array(
'controller' => 'zfcuser',
'action' => 'index',
),
),
'may_terminate' => true,
'child_routes' => array(
'employer' => array(
'type' => 'Literal',
'options' => array(
'route' => '/employer',
'defaults' => array(
'controller' => 'ZfcUser\Controller\Employer',
'action' => 'index',
),
),
'may_terminate' => true,
'child_routes' => array(
'edit' => array(
'type' => 'Segment',
'options' => array(
'route' => '/edit[/:id]',
'constraints' => array(
'id' => '[0-9]+'
),
'defaults' => array(
'controller' => 'ZfcUser\Controller\Employer',
'action' => 'edit'
)
),
),
),
),
),
),
),
),
当我运行链接时:domain.com/user/employer/edit/1
=>错误:Route with name "edit" does not have child routes
=>如何解决它
答案 0 :(得分:3)
我认为您不需要在路由配置中添加edit
作为子路由。如果我正确理解了您的情况,edit
是action
,那么您可以将其添加为employer
路由juste中的选项,如下所示:
'router' => array(
'routes' => array(
'zfcuser' => array(
'type' => 'Literal',
'options' => array(
'route' => '/user',
'defaults' => array(
'controller' => 'zfcuser',
'action' => 'index',
),
),
'may_terminate' => true,
'child_routes' => array(
'employer' => array(
'type' => 'segment',
'options' => array(
'route' => '/employer/[:action[/:id]]',
'constraints' => array(
'action' => '[a-zA-Z][a-zA-Z0-9_-]*',
'id'=>'[0-9]+'),
'defaults' => array(
'controller' => 'ZfcUser\Controller\Employer',
'action' => 'index',
)
),
),
),
),
),
),
希望这有帮助!