【问题标题】:Child routes are not working子路线不起作用
【发布时间】:2017-03-23 10:26:56
【问题描述】:

我是 Zend-Framework3 的新手。

并将我的 ZF2 应用程序迁移到 ZF3。

在这个子路由不工作。

这是我module.config.php的路由器

'router' => [
    'routes' => [
        'application' => [
            'type' => Segment::class,
            'options' => [
                'route' => '/application',
                'defaults' => [
                    'controller' => Controller\IndexController::class,
                    'action' => 'index',
                ],
            ],
            'may_terminate' => true,
            'child_routes' => [
                'kk' => [
                    'type' => Literal::class,
                    'options' => [
                        'route' => 'kk',
                        'defaults' => [
                            'controller' => Controller\IndexController::class,
                            'action' => 'kk'
                        ],
                    ],
                ],
            ]
        ]
    ],
],

当我尝试调用/application/kk 操作时。它生成404 error

我哪里错了?还是我必须手动注册所有操作?

【问题讨论】:

    标签: php zend-framework routing zend-route zend-framework3


    【解决方案1】:

    ...我必须手动注册所有操作吗?

    不,您只是在路由值中缺少 / 字符

    'router' => [
        'routes' => [
            'application' => [
                'type' => Segment::class,
                'options' => [
                    'route' => '/application',
                    'defaults' => [
                        'controller' => Controller\IndexController::class,
                        'action' => 'index',
                    ],
                ],
                'may_terminate' => true,
                'child_routes' => [
                    'kk' => [
                        'type' => Literal::class,
                        'options' => [
                            'route' => '/kk', <-- here
                            'defaults' => [
                                'controller' => Controller\IndexController::class,
                                'action' => 'kk'
                            ],
                        ],
                    ],
                ]
            ]
        ],
    ],
    

    只要存在kk 操作,就不会出现 404 错误。

    如果您的路线与操作名称相同。你可以使用Segment 输入:

        'application' => [
            'type'    => Segment::class,
            'options' => [
                'route'    => '/application[/:action]',
                'constraints' => [
                    'action' => '[a-zA-Z][a-zA-Z0-9_-]*'
                ],
                'defaults' => [
                    'controller' => Controller\IndexController::class,
                    'action'     => 'index',
                ],
            ],
        ]
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-10-02
      • 2013-05-03
      • 2014-09-08
      • 2015-04-09
      • 2015-03-18
      • 1970-01-01
      相关资源
      最近更新 更多