Skip to content

Commit 9e322d2

Browse files
committed
add back getDoctrine() in some more places
1 parent da156dd commit 9e322d2

File tree

2 files changed

+15
-14
lines changed

2 files changed

+15
-14
lines changed

doctrine.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -506,7 +506,7 @@ a controller, this is pretty easy. Add the following method to the
506506
{
507507
// you can fetch the EntityManager via $this->getDoctrine()
508508
// or you can add an argument to your action: createAction(EntityManagerInterface $em)
509-
$em = $this->get('doctrine')->getManager();
509+
$em = $this->getDoctrine()->getManager();
510510

511511
$product = new Product();
512512
$product->setName('Keyboard');

doctrine/multiple_entity_managers.rst

+14-13
Original file line numberDiff line numberDiff line change
@@ -185,21 +185,19 @@ When working with multiple entity managers to update your schema:
185185
If you *do* omit the entity manager's name when asking for it,
186186
the default entity manager (i.e. ``default``) is returned::
187187

188-
use Doctrine\ORM\EntityManagerInterface;
189-
use Doctrine\Common\Persistence\ManagerRegistry;
188+
// ...
190189

191190
class UserController extends Controller
192191
{
193-
public function indexAction(EntityManagerInterface $em, ManagerRegistry $doctrine)
192+
public function indexAction()
194193
{
195-
// All 4 return the "default" entity manager
196-
// $em from the EntityManagerInterface
197-
$em = $doctrine->getManager();
198-
$em = $doctrine->getManager('default');
194+
// All 3 return the "default" entity manager
195+
$em = $this->getDoctrine()->getManager();
196+
$em = $this->getDoctrine()->getManager('default');
199197
$em = $this->get('doctrine.orm.default_entity_manager');
200198

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

211209
The same applies to repository calls::
212210

213-
use Doctrine\Common\Persistence\ManagerRegistry;
214211
use AcmeStoreBundle\Entity\Customer;
215212
use AcmeStoreBundle\Entity\Product;
213+
// ...
216214

217215
class UserController extends Controller
218216
{
219-
public function indexAction(ManagerRegistry $doctrine)
217+
public function indexAction()
220218
{
221219
// Retrieves a repository managed by the "default" em
222-
$products = $doctrine->getRepository(Product::class)
220+
$products = $this->getDoctrine()
221+
->getRepository(Product::class)
223222
->findAll()
224223
;
225224

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

231231
// Retrieves a repository managed by the "customer" em
232-
$customers = $doctrine->getRepository(Customer::class, 'customer')
232+
$customers = $this->getDoctrine()
233+
->getRepository(Customer::class, 'customer')
233234
->findAll()
234235
;
235236
}

0 commit comments

Comments
 (0)