我正在开发一个 ZF2 系统,它运行得很好,但是在我在其他计算机上克隆存储库后,出现了这个不推荐使用的错误:
您正在从类 Module\Controller\Controller 中检索服务定位器。请注意,ServiceLocatorAwareInterface 已弃用,将在 3.0 版中与 ServiceLocatorAwareInitializer 一起删除。您将需要更新您的类以在创建时接受所有依赖项,通过构造函数参数或设置器,并使用工厂执行注入。在 /home/path/project/vendor/zendframework/zend-mvc/src/Controller/AbstractController.php 第 258 行
作曲家.json:
"require": {
"php": ">=5.5",
"ext-curl": "*",
"ext-json": "*",
"ext-mbstring": "*",
"zendframework/zendframework": "~2.5",
"doctrine/doctrine-orm-module": "0.*",
"hounddog/doctrine-data-fixture-module": "0.0.*",
"imagine/Imagine": "~0.5.0"
当我在控制器中检索服务时出现错误(扩展 Zend\Mvc\Controller\AbstractActionController):
$this->getServiceLocator()->get("Module\Service\Service");
在 Zend 核心中 Zend\Mvc\Controller\AbstractController 是这样的:
public function getServiceLocator()
{
trigger_error(sprintf(
'You are retrieving the service locator from within the class %s. Please be aware that '
. 'ServiceLocatorAwareInterface is deprecated and will be removed in version 3.0, along '
. 'with the ServiceLocatorAwareInitializer. You will need to update your class to accept '
. 'all dependencies at creation, either via constructor arguments or setters, and use '
. 'a factory to perform the injections.',
get_class($this)
), E_USER_DEPRECATED);
return $this->serviceLocator;
}
之前只有这个:
public function getServiceLocator()
{
return $this->serviceLocator;
}
我已经尝试了一切,有人知道我该怎么做吗?