You are viewing revision #2 of this wiki article.
This version may not be up to date with the latest version.
You may want to view the differences to the latest version or see the changes made in this revision.
After installing Yii basic application on our systems, most of the time we want to have multiple environment such as local, dev and live setup. Most of the times when we want to make changes to configuration file, we have to over-write configurations file for each environment.
We can make this process simple, while creating config file for each environment and adding a constant variable to index.php file to active a specific environment.
Following are the steps:
Step # 1 ¶
Add the following code to index.php
define(ENV, 'local');
// change the following paths if necessary
$yii=dirname(__FILE__).'/../yiiroot/framework/yii.php';
if (ENV == 'local') $config=dirname(__FILE__).'/protected/config/main-local.php';
if (ENV == 'dev') $config=dirname(__FILE__).'/protected/config/main-dev.php';
if (ENV == 'live') $config=dirname(__FILE__).'/protected/config/main.php';
Setp # 2 ¶
Create two files 'main-local.php' and 'main-dev.php' inside '/protected/config/' folder. These two files should be exact copy of main.php file.
Setp # 3 ¶
Make changes to each configuration file according to your requirements and then in 'index.php' set the constant variable to either
- local
- dev
- live
as per environment setup.
As we know that there are many other advance approaches available, but this is a simple way to work with multiple environment.
good
thanks for wiki, this is a good and we can put config debug in dev or local,
if(ENV == 'dev' or ENV=='local' )
{
defined('YII_DEBUG') or define('YII_DEBUG',true);
defined('YII_TRACE_LEVEL') or define('YII_TRACE_LEVEL',3);
}
simple
Hi there. That is really a useful but simple approach. If you work with automatic deployments, you don't want to edit a source file! So the ENV option should come from outside the code...
If you have any questions, please ask in the forum instead.
Signup or Login in order to comment.