Skip to content

Commit ffa8f76

Browse files
committed
minor #3545 Example of getting entity managers directly from the container (colinodell)
This PR was merged into the 2.3 branch. Discussion ---------- 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()`](https://github.com/doctrine/DoctrineBundle/blob/v1.0.0/DependencyInjection/DoctrineExtension.php#L342) | Q | A | ------------- | --- | Doc fix? | no | New docs? | yes? (added example of existing feature) | Applies to | all (doctrine/doctrine-bundle v1.0.0+) | Fixed tickets | n/a Commits ------- eb7594c Example of getting entity managers directly from the container
2 parents 6a2a55b + eb7594c commit ffa8f76

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

cookbook/doctrine/multiple_entity_managers.rst

+5-2
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)