儿童路线不起作用(Child routes are not working)

编程入门 行业动态 更新时间:2024-10-12 20:28:35
儿童路线不起作用(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 。

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

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', ], ], ]

更多推荐

本文发布于:2023-08-07 15:15:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1464534.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:不起作用   路线   儿童   working   routes

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!