-2

Can you suggest me a solution, how to get access to Doctrine from a Service in Symfony 3? I send an object of Doctrine from Controller to created Service object in a constructor but I not sure if it is the best option.

Could you recommend me a better solution?

 public function editGroupAction($groupId) {
   $doctrine = $this->getDoctrine();
   $roleHelper = new RoleHelper($doctrine);
}
Ruben Lech
  • 125
  • 12
  • Where is your code? One of the main requirements on SO is to provide a [Minimal, Complete, and Verifiable example](https://stackoverflow.com/help/mcve) – Helenesh Mar 01 '19 at 10:22
  • @Helenesh I added an example – Ruben Lech Mar 01 '19 at 10:28
  • Possible duplicate of [Symfony2 Use Doctrine in Service Container](https://stackoverflow.com/questions/8342031/symfony2-use-doctrine-in-service-container/45269646#45269646) – Fabian Schmick Mar 01 '19 at 12:35

1 Answers1

5

You can inject it like this:

use Doctrine\ORM\EntityManagerInterface;

private $em;

public function __construct(EntityManagerInterface $entityManager) {
    $this->em = $entityManager;
}