d00*_*001 12 symfony doctrine-orm symfony-2.1
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');
Run Code Online (Sandbox Code Playgroud)
We can inject the default manager to any service by using:
"@doctrine.orm.entity_manager"
Run Code Online (Sandbox Code Playgroud)
How can you inject non-default entity managers into services?
Mun*_*Das 29
如果您的实体经理配置名称,non_default
那么您可以将其引用为@doctrine.orm.non_default_entity_manager
对于使用 Symfony 3+ 的用户,请使用控制台:
php bin/console debug:container
然后你应该看到许多以 'doctrine.orm.MY_CUSTOM_ENTITY_MANAGER_xxxxxxxxxx' 开头的行
因此,如果您想要与您的自定义实体管理器相对应的实体管理器,请找到以下行:'doctrine.orm.MY_CUSTOM_ENTITY_MANAGER_entity_manager'
您可以将它插入到您的服务参数中。
希望能帮助到你。
归档时间: |
|
查看次数: |
8910 次 |
最近记录: |