Get Working Environment in Symfony

Get Working Environment in Symfony

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… 🙂

Leave a Reply

Your email address will not be published. Required fields are marked *

My new Snowflake Blog is now live. I will not be updating this blog anymore but will continue with new contents in the Snowflake world!