我正在开发一个ZF2系统并且它工作得非常好,但是在我在其他计算机中克隆存储库之后,这个已弃用的错误已经出现:
您正在从Module\Controller\Controller类中检索服务定位器.请注意,ServiceLocatorAwareInterface已弃用,将在3.0版中与ServiceLocatorAwareInitializer一起删除.您需要更新您的类以在创建时接受所有依赖项,通过构造函数参数或setter,并使用工厂执行注入.在第258行的/home/path/project/vendor/zendframework/zend-mvc/src/Controller/AbstractController.php中
composer.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"
Run Code Online (Sandbox Code Playgroud)
我在控制器中检索服务时出现错误(扩展Zend\Mvc\Controller\AbstractActionController):
$this->getServiceLocator()->get("Module\Service\Service");
Run Code Online (Sandbox Code Playgroud)
在Zend\Mvc\Controller\AbstractController的Zend核心中是这样的:
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 …Run Code Online (Sandbox Code Playgroud) php zend-framework deprecated zend-framework2 zend-framework3