8000 Example of getting entity managers directly from the container · symfony/symfony-docs@eb7594c · GitHub
[go: up one dir, main page]

Skip to content

Commit eb7594c

Browse files
committed
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)
1 parent 003230f commit eb7594c

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

cookbook/doctrine/multiple_entity_managers.rst

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,11 +187,14 @@ the default entity manager (i.e. ``default``) is returned::
187187
{
188188
public function indexAction()
189189
{
190-
// both return the "default" em
190+
// All three return the "default" entity manager
191191
$em = $this->get('doctrine')->getManager();
192192
$em = $this->get('doctrine')->getManager('default');
193+
$em = $this->get('doctrine.orm.default_entity_manager');
193194

194-
$customerEm = $this->get('doctrine')->getManager('customer');
195+
// Both of these return the "customer" entity manager
196+
$customerEm = $this->get('doctrine')->getManager('customer');
197+
$customerEm = $this->get('doctrine.orm.customer_entity_manager');
195198
}
196199
}
197200

0 commit comments

Comments
 (0)
0