子路由不起作用
Child routes are not working
我是 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
.
我哪里错了?还是我必须手动注册所有操作?
...do I have to register all actions manually?
不,您只是在路由值中缺少 /
个字符
'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',
],
],
]
我是 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
.
我哪里错了?还是我必须手动注册所有操作?
...do I have to register all actions manually?
不,您只是在路由值中缺少 /
个字符
'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',
],
],
]