Zf3:每个模块中类似的Controller
Zf3: similar Controllers in each module
我的 ZF2 应用程序中有不同的模块,每个模块都包含一个控制器列表。现在在 zf2 中创建路由和使用服务定位器获取实体管理器是不同的。现在在 Zf3 中,我们需要添加 "aliases" 和 "factories" 以使用那里的任何资源,因为在为每个模块创建路由时,即使在不同的模块中,也无法为控制器添加相同的别名;
这是我的申请/module.conf.php
'controllers' => [
'factories' => [
Controller\IndexController::class => ServiceLocatorControllerFactory::class,
Controller\UserController::class => ServiceLocatorControllerFactory::class,
],
'aliases' => [
'index' => IndexController::class,
'user' => UserController::class,
]
],
和我的仪表板/module.config.php
"controllers" => [
'factories' => [
Controller\UserController::class => ServiceLocatorControllerFactory::class,
Controller\WidgetController::class => ServiceLocatorControllerFactory::class,
],
'aliases' => [
"user" => UserController::class,
"widget" => WidgetController::class,
]
],
现在当我尝试访问 /application/user/index
它转到仪表板 => 用户控制器 => IndexAction
而不是 Application => UserController => IndexAction
我现在的解决方案是为每个控制器手动创建路由,这对我来说真的很难,因为应用程序非常大并且有 100 个控制器。另外,编写每条路线是一项多余的任务。有没有办法解决这个问题
由于在不同模块中没有找到类似模块的答案,我为每个模块中的每个控制器创建了单独的路由。这是我为
写的路线
Application-> IndexController
'application-index' => [
'type' => Segment::class,
'options' => [
'route' => '/application/index[/][:action][/]',
'defaults' => [
'__NAMESPACE__' => 'Application\Controller',
'controller' => IndexController::class,
'action' => 'index'
],
]
],
我为我的应用程序中的每个控制器都创建了。
我的 ZF2 应用程序中有不同的模块,每个模块都包含一个控制器列表。现在在 zf2 中创建路由和使用服务定位器获取实体管理器是不同的。现在在 Zf3 中,我们需要添加 "aliases" 和 "factories" 以使用那里的任何资源,因为在为每个模块创建路由时,即使在不同的模块中,也无法为控制器添加相同的别名;
这是我的申请/module.conf.php
'controllers' => [
'factories' => [
Controller\IndexController::class => ServiceLocatorControllerFactory::class,
Controller\UserController::class => ServiceLocatorControllerFactory::class,
],
'aliases' => [
'index' => IndexController::class,
'user' => UserController::class,
]
],
和我的仪表板/module.config.php
"controllers" => [
'factories' => [
Controller\UserController::class => ServiceLocatorControllerFactory::class,
Controller\WidgetController::class => ServiceLocatorControllerFactory::class,
],
'aliases' => [
"user" => UserController::class,
"widget" => WidgetController::class,
]
],
现在当我尝试访问 /application/user/index
它转到仪表板 => 用户控制器 => IndexAction
而不是 Application => UserController => IndexAction
我现在的解决方案是为每个控制器手动创建路由,这对我来说真的很难,因为应用程序非常大并且有 100 个控制器。另外,编写每条路线是一项多余的任务。有没有办法解决这个问题
由于在不同模块中没有找到类似模块的答案,我为每个模块中的每个控制器创建了单独的路由。这是我为
写的路线Application-> IndexController
'application-index' => [
'type' => Segment::class,
'options' => [
'route' => '/application/index[/][:action][/]',
'defaults' => [
'__NAMESPACE__' => 'Application\Controller',
'controller' => IndexController::class,
'action' => 'index'
],
]
],
我为我的应用程序中的每个控制器都创建了。