Answer the question
In order to leave comments, you need to log in
Is there a fundamental difference between injecting a Repository into a function and getting it through the entityManager (see code)?
The data can be obtained like this:
public function list(ItemRepository $itemRepository)
{
$items = $itemRepository->findAll();
public function list()
{
$entityManager = $this->getDoctrine()->getManager();
$items = $entityManager->getRepository(Item::class)->findAll();
Answer the question
In order to leave comments, you need to log in
If you just need to get some data from the repository, then the first option is better.
But if you need to somehow change the received data, then the second option is better, because. you can immediately pull persist and flush from em.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question