如何将Doctrine Entity Manager配置为公共Symfony服务?

时间:2019-06-03 12:01:12

标签: php symfony symfony-3.4

我想将Doctrine Entity Manager配置为公共Symfony服务。

我尝试在services.yml中添加以下配置块(一次添加一个):

Doctrine\ORM\EntityManagerInterface:                                                                                
    public: true            
# [OUTPUT] Error: Cannot instantiate interface Doctrine\ORM\EntityManagerInterface                                                                       

Doctrine\ORM\EntityManager:                                                                                         
    public: true                                                                                                    
# [OUTPUT] Invalid service "Doctrine\ORM\EntityManager": its constructor must be public.

doctrine.orm.default_entity_manager:                                                                                
    public: true  
# [OUTPUT] The definition for "doctrine.orm.default_entity_manager" has no class. If you intend to inject this service dynamically at runtime, please mark it as synthetic=true. If this is an abstract definition solely used by child definitions, please add abstract=true, otherwise specify a class to get rid of this error.

从输出错误消息来看,我怀疑定义不完整,但是在任何地方都找不到手动配置Doctrine Entity Manager服务的正确方法。

1 个答案:

答案 0 :(得分:0)

根据塞拉德的评论,我不得不添加alias: 'doctrine.orm.default_entity_manager' 到我第一次尝试的配置。

因此正确的解决方案是:

Doctrine\ORM\EntityManagerInterface:                                                                                
    public: true
    alias: 'doctrine.orm.default_entity_manager'