@@ -185,21 +185,19 @@ When working with multiple entity managers to update your schema:
185
185
If you *do * omit the entity manager's name when asking for it,
186
186
the default entity manager (i.e. ``default ``) is returned::
187
187
188
- use Doctrine\ORM\EntityManagerInterface;
189
- use Doctrine\Common\Persistence\ManagerRegistry;
188
+ // ...
190
189
191
190
class UserController extends Controller
192
191
{
193
- public function indexAction(EntityManagerInterface $em, ManagerRegistry $doctrine )
192
+ public function indexAction()
194
193
{
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');
199
197
$em = $this->get('doctrine.orm.default_entity_manager');
200
198
201
199
// Both of these return the "customer" entity manager
202
- $customerEm = $doctrine ->getManager('customer');
200
+ $customerEm = $this->getDoctrine() ->getManager('customer');
203
201
$customerEm = $this->get('doctrine.orm.customer_entity_manager');
204
202
}
205
203
}
@@ -210,26 +208,29 @@ entity manager to persist and fetch its entities.
210
208
211
209
The same applies to repository calls::
212
210
213
- use Doctrine\Common\Persistence\ManagerRegistry;
214
211
use AcmeStoreBundle\Entity\Customer;
215
212
use AcmeStoreBundle\Entity\Product;
213
+ // ...
216
214
217
215
class UserController extends Controller
218
216
{
219
- public function indexAction(ManagerRegistry $doctrine )
217
+ public function indexAction()
220
218
{
221
219
// Retrieves a repository managed by the "default" em
222
- $products = $doctrine->getRepository(Product::class)
220
+ $products = $this->getDoctrine()
221
+ ->getRepository(Product::class)
223
222
->findAll()
224
223
;
225
224
226
225
// Explicit way to deal with the "default" em
227
- $products = $doctrine->getRepository(Product::class, 'default')
226
+ $products = $this->getDoctrine()
227
+ ->getRepository(Product::class, 'default')
228
228
->findAll()
229
229
;
230
230
231
231
// Retrieves a repository managed by the "customer" em
232
- $customers = $doctrine->getRepository(Customer::class, 'customer')
232
+ $customers = $this->getDoctrine()
233
+ ->getRepository(Customer::class, 'customer')
233
234
->findAll()
234
235
;
235
236
}
0 commit comments