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
How should I get to the container?
Thanks :)
You should not use $container in the EntityRepository. Instead, create a Model Manager service and inject the container through DI.
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 =),
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With