doucheng4094
doucheng4094
2015-02-04 10:16
浏览 25
已采纳

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

I'm using ZfcUser module for Zend Framework 2 In Controller folder Controller

--UserController.php
--EmployerController.php

In module.config.php, I config with 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'
                                    )
                                ),
                            ),
                        ),
                      ),
                ),  
          ),
     ),
),

When I run link: domain.com/user/employer/edit/1

=> error: Route with name "edit" does not have child routes => How to fix it

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • douliaopan1419
    douliaopan1419 2015-02-04 11:08
    已采纳

    I think you don't need to add the edit as a child route in your routing configuration. If I correctly understood your case, edit is an action so you could just add it as an option in the employer route juste like this :

    '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',
                             )
                    ),
                ),
            ),
        ),
    ),
    ),
    

    Hope this could help !

    点赞 评论
  • dongzhankou2090
    dongzhankou2090 2015-07-15 05:27

    The arrays indexed by may_terminate and child_routes should be moved into employer

    点赞 评论

相关推荐