我是新来的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。
我哪里错了?还是必须手动注册所有操作?
发布于 2017-03-23 10:48:24
...do我必须手动注册所有操作?
不,您只是在路由值中缺少了/字符。
'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',
],
],
]https://stackoverflow.com/questions/42973368
复制相似问题