ZF2:ServiceLocatorAwareInterface已弃用,将在3.0版中删除

时间:2016-03-04 22:57:26

标签: php zend-framework2

如何修复它(zend版本2.5)?

ServiceLocatorAwareInterface已弃用,将在3.0版中与ServiceLocatorAwareInitializer一起删除。请更新您的班级Teacher \ Controller \ TeacherController以删除实现,并开始通过工厂注入您的依赖项

我试过了:

class TeacherControllerFactory implements FactoryInterface
    {
        public function __invoke(ContainerInterface $container, $name, array $options = null)
        {
            return new TeacherController(
                $container->getServiceLocator()->get(TeacherService::class)
            );
        }

        /**
         * Create and return TeacherController instance
         *
         * For use with zend-servicemanager v2; proxies to __invoke().
         *
         * @param ServiceLocatorInterface $container
         * @return TeacherController
         */
        public function createService(ServiceLocatorInterface $container)
        {
            return $this($container, TeacherController::class);
        }
    }

2 个答案:

答案 0 :(得分:4)

看看here。补丁已经合并。这是link to the patch

This Link帮助我正确注入依赖关系。

答案 1 :(得分:0)

您需要添加 ~E_USER_DEPRECATED

您可以添加public / index.php

ini_set ( "error_reporting", E_ALL & ~ E_DEPRECATED & ~E_USER_DEPRECATED  & ~ E_STRICT );

error_reporting ( E_ALL & ~ E_DEPRECATED & ~ E_USER_DEPRECATED & ~ E_STRICT );
  

用户生成的警告消息。这就像E_DEPRECATED,除了   它是使用PHP函数trigger_error()在PHP代码中生成的。

http://php.net/manual/en/errorfunc.constants.php