在 symfony2.7 中使用工厂创建服务
Using a Factory to Create Services with symfony2.7
symfony2.7如何使用工厂创建服务?
#service.yml
#in symfony 2.6
my.repository.photo:
class: My\AppBundle\Repository\PhotoRepository
factory_method: getRepository
factory_service: doctrine
arguments: [My\AppBundle\Entity\Photo]
#I have some errors like this
Deprecated: Symfony\Component\DependencyInjection\Definition::setFactoryMethod(getRepository) is deprecated since version 2.6 and will be removed in 3.0. Use Definition::setFactory() instead. in /my/vendor/symfony/symfony/src/Symfony/Component/DependencyInjection/Definition.php on line 137
Deprecated: Symfony\Component\DependencyInjection\Definition::setFactoryService(doctrine) is deprecated since version 2.6 and will be removed in 3.0. Use Definition::setFactory() instead. in my/vendor/symfony/symfony/src/Symfony/Component/DependencyInjection/Definition.php on line 208
我现在如何使用 "setFactory" 方法?
文档:http://symfony.com/doc/master/components/dependency_injection/factories.html
谢谢!
我觉得相关文档写的很清楚。试试这个配置:
my.repository.photo:
class: My\AppBundle\Repository\PhotoRepository
factory: ["@doctrine", getRepository]
arguments: [My\AppBundle\Entity\Photo]
已弃用的错误是为即将推出的 Symfony 3.0 做准备。一些功能(如 factory_service|factory_method)将被删除。这是一个线程,如果您真的不需要它,您可以在其中找到解决方案 。
symfony2.7如何使用工厂创建服务?
#service.yml
#in symfony 2.6
my.repository.photo:
class: My\AppBundle\Repository\PhotoRepository
factory_method: getRepository
factory_service: doctrine
arguments: [My\AppBundle\Entity\Photo]
#I have some errors like this
Deprecated: Symfony\Component\DependencyInjection\Definition::setFactoryMethod(getRepository) is deprecated since version 2.6 and will be removed in 3.0. Use Definition::setFactory() instead. in /my/vendor/symfony/symfony/src/Symfony/Component/DependencyInjection/Definition.php on line 137
Deprecated: Symfony\Component\DependencyInjection\Definition::setFactoryService(doctrine) is deprecated since version 2.6 and will be removed in 3.0. Use Definition::setFactory() instead. in my/vendor/symfony/symfony/src/Symfony/Component/DependencyInjection/Definition.php on line 208
我现在如何使用 "setFactory" 方法? 文档:http://symfony.com/doc/master/components/dependency_injection/factories.html
谢谢!
我觉得相关文档写的很清楚。试试这个配置:
my.repository.photo:
class: My\AppBundle\Repository\PhotoRepository
factory: ["@doctrine", getRepository]
arguments: [My\AppBundle\Entity\Photo]
已弃用的错误是为即将推出的 Symfony 3.0 做准备。一些功能(如 factory_service|factory_method)将被删除。这是一个线程,如果您真的不需要它,您可以在其中找到解决方案