How do I use Doctrine in a service container?
The Code just causes an error message \"Fatal error: Call to undefined method ...::get()\".
in the Symfony 3.4. If you want to use Doctrine in a service you can do it: Only this method worked for me
services.yml:
YourBundle\PatchService\YourService:
public: true
arguments: [ '@doctrine.orm.entity_manager' ]
Service:
class YourService
{
private $em;
public function __construct($em) {
$this->em = $em;
}
Controller:
use YourBundle\PatchService\YourService;
/**
* @Route("/YourController/",name="YourController")
*/
public function indexAction()
{
$em = $this->getDoctrine()->getManager();
$Notification = new YourService($em);