membuat environment development testing dan production

pada yii di index file kita akan merubah / menambah

[code]
//choose environment development
$appEnv = filter_input(INPUT_ENV, ‘APPLICATION_ENV’, FILTER_SANITIZE_ENCODED);
$serverName = filter_input(INPUT_SERVER, "SERVER_NAME", FILTER_SANITIZE_SPECIAL_CHARS);
if (!isset($appEnv)) {
if (true === stripos($serverName, ‘localhost’)) {
$appEnv = "development";
} else
if (true === stripos($serverName, ‘www.meltonice.com’)) {
$appEnv = "testing";
} else
if (true === stripos($serverName, ‘www.kresna.host’)) {
$appEnv = "production";
} else {
$appEnv = "development";
}
}
if ($appEnv == "production") {
$config = dirname(__FILE__) . ‘/protected/config/production.php’;
}
if ($appEnv == "development") {
// remove the following lines when in production mode
defined(‘YII_DEBUG’) or define(‘YII_DEBUG’, true);
$config = dirname(__FILE__) . ‘/protected/config/main.php’;
}
if ($appEnv == "testing") {
$config = dirname(__FILE__) . ‘/protected/config/testing.php’;
}

[/code]

sehingga kita dapat membuat file config masing2 dan tanpa repot untuk merubah setting dan konfigurasi untuk database, logging dan lain sebagainya 😀

membuat multiple application environment

pada web apps kita sering mempunyai beberapa settingan berbeda untuk koneksi database dan fitur config lainnya

mulai dari stage development, testing hingga production

berikut adalah cara untuk setting multiple app environment pada YII framework

sebagai contoh berikut adalah setting yang saya pakai di index.php

[code]

//choose environment development
$appEnv = filter_input(INPUT_ENV, ‘APPLICATION_ENV’, FILTER_SANITIZE_ENCODED);
$serverName = filter_input(INPUT_SERVER, "SERVER_NAME", FILTER_SANITIZE_SPECIAL_CHARS);
if (!isset($appEnv)) {
if (FALSE === stripos($serverName, ‘localhost’)) {
$appEnv = "development";
} else
if (FALSE === stripos($serverName, ‘www.meltonice.com’)) {
$appEnv = "testing";
} else
if (FALSE === stripos($serverName, ‘www.usa4u.com’)) {
$appEnv = "production";
} else {
$appEnv = "development";
}
}
if ($appEnv == "production") {
$config = dirname(__FILE__) . ‘/protected/config/production.php’;
}
if ($appEnv == "development") {
$config = dirname(__FILE__) . ‘/protected/config/main.php’;
}
if ($appEnv == "testing") {
$config = dirname(__FILE__) . ‘/protected/config/testing.php’;
}

[/code]