Skip to content

Instantly share code, notes, and snippets.

@wangshijun
Created August 27, 2012 08:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wangshijun/3486700 to your computer and use it in GitHub Desktop.
Save wangshijun/3486700 to your computer and use it in GitHub Desktop.
php: environment dependent config autoloading Yii startup
<?php
define("APP_DIR", dirname(dirname(__FILE__)));
define("WWW_DIR", dirname(APP_DIR));
define("CONF_DIR", APP_DIR . "/protected/config/");
$clusters = require_once(CONF_DIR . "clusters.php");
$mainConfig = require_once(CONF_DIR . "main.php");
// 根据应用程序所在环境加载配置, 默认为develop
if (isset($clusters["product"]) && in_array(strtolower(php_uname("n")), $clusters["product"])) {
defined("YII_DEBUG") || define("YII_DEBUG", false);
defined("YII_TRACE_LEVEL") or define("YII_TRACE_LEVEL", 0);
$clusterConfig = require_once(CONF_DIR . "conf.d/product.php");
} else {
defined("YII_DEBUG") || define("YII_DEBUG", true);
defined("YII_TRACE_LEVEL") or define("YII_TRACE_LEVEL", 3);
$clusterConfig = require_once(CONF_DIR . "conf.d/develop.php");
}
require_once (WWW_DIR . "/thirdlib/yii/framework/yii.php");
Yii::setPathOfAlias("jike", WWW_DIR . "/jikelib"); //jike namespace
Yii::setPathOfAlias("third", WWW_DIR . "/thirdlib"); //third namespace
Yii::import("jike.yiiext.*"); //import jike.yiiext
Yii::import("third.*"); //import third
$GLOBALS ["THRIFT_ROOT"] = APP_DIR . "/protected/lib/thrift/";
// Run Application
$config = CMap::mergeArray($mainConfig, $clusterConfig);
Yii::createWebApplication($config)->run();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment