Revision #4 has been created by nancoder on Oct 5, 2010, 7:07:11 AM with the memo:
Misspelling: Replaced "enviroment" to "environment"
« previous (#3) next (#5) »
Changes
Title
changed
Use different environments (development, production, etc) in your app with EASY Environment Class
Category
unchanged
Tutorials
Yii version
unchanged
Tags
unchanged
Content
changed
[...]
Instructions
============
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...
}[...]