php - Zf3:每个模块中的类似Controllers
问题描述
我的 ZF2 应用程序中有不同的模块,每个模块都包含一个控制器列表。现在在 zf2 中创建路由和获取带有服务定位器的实体管理器是不同的。现在在 Zf3 中,我们需要添加“别名”和“工厂”以使用那里的任何资源,因为在为每个模块创建路由时,即使在不同的模块中也无法为控制器添加相同的别名;
这是我的应用程序/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
它转到仪表板 => UserController => IndexAction
而不是 Application => UserController => IndexAction
我现在的解决方案是为每个控制器手动创建路由,这在我的情况下真的很难,因为应用程序非常大并且有 100 个控制器。另外,写每条路线有点多余。有没有办法解决问题
解决方案
由于没有为不同模块中的类似模块找到答案,我为每个模块中的每个控制器创建了单独的路由。这是我写的路线
应用程序-> 索引控制器
'application-index' => [
'type' => Segment::class,
'options' => [
'route' => '/application/index[/][:action][/]',
'defaults' => [
'__NAMESPACE__' => 'Application\Controller',
'controller' => IndexController::class,
'action' => 'index'
],
]
],
我为我的应用程序中的每个控制器创建了。
推荐阅读
- javascript - 在圆周上设置线条
- azure - 如何在 Azure Devops 中工作项的描述部分创建本地文件链接?
- c# - Firebase 实时数据库的 Unity 错误
- python - 硒与python如何点击弹出按钮
- mysql - 使用 MYSQL,如果表已经存在,我如何查询它?
- c# - ObservableCollection 列表找不到方法 AddRange
- javascript - JavaScript 重定向到基于 URL 的另一个网站
- python - Google Cloud 中的 UMAP 模型加载失败,字节码版本不兼容
- c - 为什么断言不做任何事情?我需要做什么才能让它工作?
- rabbitmq - 响应 RabbitMQ API GET /api/queues 的密钥重复的可能原因