[英]create route for my backend website in zf3
i have in module/config/module.config.php : 我在module / config / module.config.php中:
'router' => [
'routes' => [
'home-backend' => [
'type' => Literal::class,
'options' => [
'route' => '/backend',
'defaults' => [
'controller' => Controller\IndexController::class,
'action' => 'index',
],
],
],
'backend' => [
'type' => Segment::class,
'options' => [
'route' => '/backend[/:controller[/:action]]',
'defaults' => [
'controller' => Controller\IndexController::class,
'action' => 'index',
],
],
'may_terminate' => true,
'child_routes' => [
'wildcard' => [
'type' => 'Wildcard'
]
]
],
],
],
when i call : http://mysite/backend/index/index error : Page not found. 当我打电话: http:// mysite / backend / index / index错误:找不到页面。 The requested controller could not be mapped to an existing controller class.
请求的控制器无法映射到现有的控制器类。
Controller: index (resolves to invalid controller class or alias: index) Controller:index(解析为无效的控制器类或别名:index)
what is problem?? 什么是问题?
Seem you missed configuration for controller
. 似乎你错过了
controller
配置。 Please add configuration for controller to module/config/module.config.php
. 请将控制器的配置添加到
module/config/module.config.php
。
If you use factory
, the configuration will be like this. 如果您使用
factory
,配置将如下所示。
'controllers' => [
'factories' => [
Controller\IndexController::class => Controller\IndexControllerFactory::class,
]
],
If you don't use factory
, the configuration will be like this 如果您不使用
factory
,配置将如下所示
use Zend\ServiceManager\Factory\InvokableFactory;
return [
'controllers' => [
'factories' => [
Controller\IndexController::class => InvokableFactory::class,
]
],
]
Point that you should not use same route patten twice. 指出你不应该使用相同的路线模式两次。 Here I see
/backend
is used twice. 在这里,我看到
/backend
使用了两次。 Otherwise the route pattern for backend
route is not well-formatted. 否则,
backend
路由的路由模式格式不正确。
Hope you would understand the better way here ! 希望你能理解这里更好的方式 !
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.