错误配置路由在 zend framework 2 中没有子路由?

Error Config Route does not have child routes in zend framework 2?

我正在使用 Zend Framework 2 的 ZfcUser 模块 在控制器文件夹中 控制器

--UserController.php
--EmployerController.php

在module.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'
                                    )
                                ),
                            ),
                        ),
                      ),
                ),  
          ),
     ),
),

当我运行link: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_terminatechild_routes 索引的数组应移动到 employer