我知道这已经在其他线程中得到了广泛的介绍,但是我很难弄清楚如何从ZF3控件中的ZF2控制器复制$ this-> getServiceLocator()的效果.
我尝试使用我在这里和其他地方找到的各种其他答案和教程来创建一个工厂,但最终却陷入了混乱,所以我粘贴了我的代码,就像我开始希望那样有人可以指出我正确的方向吗?
来自/module/Application/config/module.config.php
'controllers' => [
'factories' => [
Controller\IndexController::class => InvokableFactory::class,
],
],
Run Code Online (Sandbox Code Playgroud)
来自/module/Application/src/Controller/IndexController.php
public function __construct() {
$this->objectManager = $this->getServiceLocator()->get('Doctrine\ORM\EntityManager');
$this->trust = new Trust;
}
Run Code Online (Sandbox Code Playgroud)