Permalink
Browse files

minor #3545 Example of getting entity managers directly from the cont…

…ainer (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
  • Loading branch information...
weaverryan committed Feb 16, 2014
2 parents 6a2a55b + eb7594c commit ffa8f76d3582fe4cc78cc788f6f9c7018ebca75e
Showing with 5 additions and 2 deletions.
  1. +5 −2 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');
}
}

0 comments on commit ffa8f76

Please sign in to comment.