Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check if in "dev" mode inside a Controller with Symfony

When using dev mode with a Symfony2.x application, one usually works in locale. Hence, such function does not works as expected (for instance, try to get the current IP under localhost). This could be a problem, e.g. when one try to use such ip-based web service. Hence, I just want to know how to check inside a controller if the Symfony2 application is running in dev mode or not. In that way one can set the behavior of the controller depending by the mode.

Any idea?

like image 270
JeanValjean Avatar asked Oct 21 '12 13:10

JeanValjean


1 Answers

To get the current environment in a Controller you can use:

$this->container->getParameter('kernel.environment'); 

So you just put that in an if() statement to check if it equals to dev.

like image 130
tolgap Avatar answered Oct 05 '22 13:10

tolgap