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 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 !

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记