From eb7594c308e6d69b247bdcf724c724863f5ffdcb Mon Sep 17 00:00:00 2001 From: Colin O'Dell Date: Wed, 5 Feb 2014 17:24:52 -0500 Subject: [PATCH] Example of getting entity managers directly from the container The documentation didn't provide examples of how to obtain the entity managers directly from the DI container. This is useful when needing to inject the em into other services. The ems are added to the container using the service id `doctrine.orm.%s_entity_manager`, where `%s` is the em's name. This is done by `\Doctrine\Bundle\DoctrineBundle\DependencyInjection\DoctrineExtension::loadOrmEntityManager()` (see: https://github.com/doctrine/DoctrineBundle/blob/v1.2.0/DependencyInjection/DoctrineExtension.php#L347) --- cookbook/doctrine/multiple_entity_managers.rst | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/cookbook/doctrine/multiple_entity_managers.rst b/cookbook/doctrine/multiple_entity_managers.rst index 40f54255ea9..e41301f00f2 100644 --- a/cookbook/doctrine/multiple_entity_managers.rst +++ b/cookbook/doctrine/multiple_entity_managers.rst @@ -187,11 +187,14 @@ the default entity manager (i.e. ``default``) is returned:: { public function indexAction() { - // both return the "default" em + // All three return the "default" entity manager $em = $this->get('doctrine')->getManager(); $em = $this->get('doctrine')->getManager('default'); + $em = $this->get('doctrine.orm.default_entity_manager'); - $customerEm = $this->get('doctrine')->getManager('customer'); + // Both of these return the "customer" entity manager + $customerEm = $this->get('doctrine')->getManager('customer'); + $customerEm = $this->get('doctrine.orm.customer_entity_manager'); } }