【问题标题】:Error Config Route does not have child routes in zend framework 2?错误配置路由在zend框架2中没有子路由?
【发布时间】:2015-02-04 10:16:31
【问题描述】:

我正在为 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'
                                    )
                                ),
                            ),
                        ),
                      ),
                ),  
          ),
     ),
),

当我运行链接时:domain.com/user/employer/edit/1

=> 错误:Route with name "edit" does not have child routes => 如何解决它

【问题讨论】:

  • 在任何视图上试试这个:= $this->url('zfcuser/employer/edit') ?>它可能有助于调试

标签: php zend-framework routes zend-framework2 router


【解决方案1】:

我认为您不需要在路由配置中添加edit 作为子路由。如果我正确理解了您的情况,editaction,因此您可以将其作为选项添加到 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',
                         )
                ),
            ),
        ),
    ),
),
),

【讨论】:

    【解决方案2】:

    may_terminatechild_routes 索引的数组应移动到 employer

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-07-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多