我正在使用ZfcUser模块进行Zend Framework 2在控制器文件夹中控制器
--UserController.php
--EmployerController.php
在模块.config.php中,我配置了路由
'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
=> 如何修复它
我认为您不需要将edit
添加为路由配置中的子路由。如果我正确理解了您的情况,edit
是一个action
,因此您可以将其作为employer
路线中的一个选项添加,如下所示:
'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',
)
),
),
),
),
),
),
按 may_terminate
和 child_routes
索引的数组应移至employer