> Info:
> An extension was created based on this wiki page. See: <http://www.yiiframework.com/extension/yii-environment/>
Hi, I was having problems each time I had to test the site or edit something on my local machine, like changing the db connection, change the debug mode to false, the trace level to 0, disable Gii, etc. So I created a class to resolve all my problems, hope to help you in your projects![...]
============
Configuring the Easy Environment class
-------------------------------------
1. Create a new file in the config folder, name it 'enviro
nment.php'.
2. Paste the following code in your 'enviro
nment.php' file.
```php
/**
* This class helps you to config your Yii application
* enviro
nment.
* Any comments please post a message in the forum
* Enjoy it!
*
* @name Enviro
nment
* @author Fernando Torres | Marciano Studio
* @version 1.0
*/
class Enviro
nment {
const DEVELOPMENT = 100;[...]
/**
* Initilizes the Environment class with the given mode
* @param constant $mode
*/[...]
/**
* Sets the configuration for the choosen environment
* @param constant $mode
*/[...]
/**
* Main configuration
* This is the general configuration that uses all environments
*/
private function _main() {[...]
'params'=>array(
'adminEmail'=>'admin@example.com',
'environment'=> $this->_mode
)
);[...]
);
}
}// END Environment Class
```
3. Change the configuration for each enviro
nment:
* DEVELOPMENT
* TEST[...]
```php
// Change the following paths if necessary
require_once(dirname(__FILE__).'/protected/config/environment.php');
$enviro
nment = new Enviro
nment(Enviro
nment::DEVELOPMENT) ;
$yii = dirname(__FILE__).'/../../framework/yii.php';
defined('YII_DEBUG') or define('YII_DEBUG',$enviro
nment->getDebug());
defined('YII_TRACE_LEVEL') or define('YII_TRACE_LEVEL', $enviro
nment->getTraceLevel());
require_once($yii);
Yii::createWebApplication($enviro
nment->getConfig())->run();
```
Changing your enviro
nment
------------------------
5. To change the enviro
nment just you have to change the following code:
```php
//For development
$enviro
nment = new Enviro
nment(Enviro
nment::DEVELOPMENT);
//For test
$enviro
nment = new Enviro
nment(Enviro
nment::TEST);
//For stage
$enviro
nment = new Enviro
nment(Enviro
nment::STAGE);
//For production
$enviro
nment = new Enviro
nment(Enviro
nment::PRODUCTION);
```
Get your actual enviro
nment
--------------------------
6. You can check inside your application in what enviro
nment you are working with the following code:
```php
// This will return the enviro
nment code number
$currentEnviro
nment = Yii::app()->getParams()->enviro
nment;
// Compare if the current enviro
nment is lower than production
if($currentEnviro
nment < Enviro
nment::PRODUCTION){
//Your code here...
}else{
//Your code here...
}[...]