How to inject non-default entity managers?

前端 未结 4 792
太阳男子
太阳男子 2020-12-28 19:01

In Symfony2 you can work with multiple entity managers and use something like the code below:

$em = $this->get(\'doctrine\')->getManager();
$em = $this         


        
4条回答
  •  爱一瞬间的悲伤
    2020-12-28 19:54

    For those who are using Symfony 3+, use the console : php bin/console debug:container

    Then you should see many lines starting with : 'doctrine.orm.MY_CUSTOM_ENTITY_MANAGER_xxxxxxxxxx'

    So if you want the entity manager corresponding to your custom entity manager, find the line : 'doctrine.orm.MY_CUSTOM_ENTITY_MANAGER_entity_manager'

    You can insert it in your service arguments.

    Hope it helps.

提交回复
热议问题