Get Symfony Container in an EntityRepository

后端 未结 5 1216
无人共我
无人共我 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:38

    Bro, Symfony sometimes or lot of times is a headache, here is a hacky way, is not the correct like the @Tuong Le answer but is a horror do a lot for just a variable like was says @keyboardSmasher.

    At the start of the function/method:

    global $kernel;
    if($kernel instanceOf \AppCache) $kernel = $kernel->getKernel();
    

    So you can acces a container with

    $kernel->getContainer();
    

    hope this gives you time to go to walk in the park =),

提交回复
热议问题