While developing a Symfony application, in lots of cases, you might want to know the current working environment and do some action accordingly. I used to use the following code to retrieve the environment:
$env = sfContext::getInstance()->getEnvironment();
However, this is a tedious and time consuming way to retrieve the data. The environment information is stored in the sfConfig object after project and application are initialised. So the better and faster way to do it is:
$env = sfConfig::get('sf_environment');
This will set $env to be ‘prod’, ‘dev’, ‘beta’ based on the environment you set in the frontend controller.
Happy Symfonying… 🙂