Symfony 2 EntityManager injection in service

后端 未结 4 1082
栀梦
栀梦 2020-11-28 23:21

I\'ve created my own service and I need to inject doctrine EntityManager, but I don\'t see that __construct() is called on my service, and injection doesn\'t wo

4条回答
  •  清酒与你
    2020-11-29 00:02

    Note as of Symfony 3.3 EntityManager is depreciated. Use EntityManagerInterface instead.

    namespace AppBundle\Service;
    
    use Doctrine\ORM\EntityManagerInterface;
    
    class Someclass {
        protected $em;
    
        public function __construct(EntityManagerInterface $entityManager)
        {
            $this->em = $entityManager;
        }
    
        public function somefunction() {
            $em = $this->em;
            ...
        }
    }
    

提交回复
热议问题