Get Symfony Container in an EntityRepository

后端 未结 5 1204
无人共我
无人共我 2020-12-15 11:56

I\'ve set a variable in parameters.ini, but now I want to retrieve that variable from an EntityRepository and $this->container is unset so I can\'t do it

5条回答
  •  囚心锁ツ
    2020-12-15 12:22

    You can retrieve your variable from the Controller as usual, and pass it to the EntityRepository if you define a custom repository method. For example:

    public function findAllOrderedByFoo($your_variable)
    {
        //use $your_variable here
    
        return $this->getEntityManager()
            ->createQuery(  your SQL here   )
            ->getResult();
    }
    

提交回复
热议问题