Skip to content

add back getDoctrine() in some more places #8137

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 11, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion doctrine.rst
Original file line number Diff line number Diff line change
Expand Up @@ -506,7 +506,7 @@ a controller, this is pretty easy. Add the following method to the
{
// you can fetch the EntityManager via $this->getDoctrine()
// or you can add an argument to your action: createAction(EntityManagerInterface $em)
$em = $this->get('doctrine')->getManager();
$em = $this->getDoctrine()->getManager();

$product = new Product();
$product->setName('Keyboard');
Expand Down
27 changes: 14 additions & 13 deletions doctrine/multiple_entity_managers.rst
Original file line number Diff line number Diff line change
Expand Up @@ -185,21 +185,19 @@ When working with multiple entity managers to update your schema:
If you *do* omit the entity manager's name when asking for it,
the default entity manager (i.e. ``default``) is returned::

use Doctrine\ORM\EntityManagerInterface;
use Doctrine\Common\Persistence\ManagerRegistry;
// ...

class UserController extends Controller
{
public function indexAction(EntityManagerInterface $em, ManagerRegistry $doctrine)
public function indexAction()
{
// All 4 return the "default" entity manager
// $em from the EntityManagerInterface
$em = $doctrine->getManager();
$em = $doctrine->getManager('default');
// All 3 return the "default" entity manager
$em = $this->getDoctrine()->getManager();
$em = $this->getDoctrine()->getManager('default');
$em = $this->get('doctrine.orm.default_entity_manager');

// Both of these return the "customer" entity manager
$customerEm = $doctrine->getManager('customer');
$customerEm = $this->getDoctrine()->getManager('customer');
$customerEm = $this->get('doctrine.orm.customer_entity_manager');
}
}
Expand All @@ -210,26 +208,29 @@ entity manager to persist and fetch its entities.

The same applies to repository calls::

use Doctrine\Common\Persistence\ManagerRegistry;
use AcmeStoreBundle\Entity\Customer;
use AcmeStoreBundle\Entity\Product;
// ...

class UserController extends Controller
{
public function indexAction(ManagerRegistry $doctrine)
public function indexAction()
{
// Retrieves a repository managed by the "default" em
$products = $doctrine->getRepository(Product::class)
$products = $this->getDoctrine()
->getRepository(Product::class)
->findAll()
;

// Explicit way to deal with the "default" em
$products = $doctrine->getRepository(Product::class, 'default')
$products = $this->getDoctrine()
->getRepository(Product::class, 'default')
->findAll()
;

// Retrieves a repository managed by the "customer" em
$customers = $doctrine->getRepository(Customer::class, 'customer')
$customers = $this->getDoctrine()
->getRepository(Customer::class, 'customer')
->findAll()
;
}
Expand Down