如何注入非默认实体经理? [英] How to inject non-default entity managers?
本文介绍了如何注入非默认实体经理?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
$ em = $ this- >获得( '教义') - > getManager();
$ em = $ this-> get('doctrine') - > getManager('default');
$ customerEm = $ this-> get('doctrine') - > getManager('customer');
我们可以通过使用以下方式将默认管理器注入到任何服务中:
@ doctrine.orm.entity_manager
如何将非默认实体管理器注入到服务中?
解决方案
如果您的实体经理配置名称为 non_default
然后您可以将其引用为 @ doctrine.orm.non_default_entity_manager
In Symfony2 you can work with multiple entity managers and use something like the code below:
$em = $this->get('doctrine')->getManager();
$em = $this->get('doctrine')->getManager('default');
$customerEm = $this->get('doctrine')->getManager('customer');
We can inject the default manager to any service by using:
"@doctrine.orm.entity_manager"
How can you inject non-default entity managers into services?
解决方案
If your entity managers config name is non_default
then you can reference it as @doctrine.orm.non_default_entity_manager
这篇关于如何注入非默认实体经理?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文