How to call Entity Manager in a constructor?

前端 未结 6 1602
终归单人心
终归单人心 2020-12-06 05:52

I\'ve been trying to call Entity Manager in a constructor:

function __construct()
{
    $this->getDoctrine()->getEntityManager();
    ...
         


        
6条回答
  •  误落风尘
    2020-12-06 06:46

    I think you are in the right direction, I would take the second option:

    For the second option I think that the definition inside routing.yml is wrong

    //routing.yml 
    msd_home_cambiardimensiones:
        pattern: /cambiardimensiones
        defaults: { _controller: msd.imagetrans.controller:cambiardimensionesAction }
    

    Here just remove MSDHomeBundle from the _controller inside defaults

    For the first option:

    Does HomeController has its own constructor?

    //src/MSD/HomeBundle/Resources/config/services.yml
    services:
        imageTransController.custom.service:
            class:  MSD\HomeBundle\Controller\ImageTransController
            arguments: [@doctrine]
    

    it could help then inside the constructor

    __construct(Registry $doctrine)
    $this->doctrine = $doctrine;
    
    or
    
    $this->em = $doctrine->getManager();
    

提交回复
热议问题