我是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 。
我哪里错了? 或者我是否必须手动注册所有操作?
I'm new to Zend-Framework3.
And migrating my ZF2 application to ZF3.
In this child routes are not working.
Here is router from my 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' ], ], ], ] ] ], ],When I try to call /application/kk action. It generates 404 error.
Where am I wrong? Or 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' ], ], ], ] ] ], ],只要action 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', ], ], ]...do I have to register all actions manually?
No, you are just missing / character in route value
'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' ], ], ], ] ] ], ],As long as action kk exists, you should not get 404 error.
If your routes are same as actions name. You can use Segment type:
'application' => [ 'type' => Segment::class, 'options' => [ 'route' => '/application[/:action]', 'constraints' => [ 'action' => '[a-zA-Z][a-zA-Z0-9_-]*' ], 'defaults' => [ 'controller' => Controller\IndexController::class, 'action' => 'index', ], ], ]更多推荐
发布评论