How to get a Respository from an Entity?

后端 未结 4 1383
遇见更好的自我
遇见更好的自我 2020-12-25 14:01

I have an Entity called Game with a related Repository called GameRepository:

/**
 * @ORM\\Entity(repositoryClass=\"...\\GameReposi         


        
4条回答
  •  不思量自难忘°
    2020-12-25 14:35

    you can inject the doctrine entity manager in your entity (using JMSDiExtraBundle) and have the repository like this:

    /**
     * @InjectParams({
     *     "em" = @Inject("doctrine.orm.entity_manager")
     * })
     */
        public function setInitialStatus(\Doctrine\ORM\EntityManager $em) {
    
    
        $obj = $em->getRepository('AcmeSampleBundle:User')->functionInRepository();
        //...
    }
    

    see this : http://jmsyst.com/bundles/JMSDiExtraBundle/1.1/annotations

提交回复
热议问题