seven2 发表于 2010-4-27 20:01:49

CodeIgniter 根据不同的二级域名来调用不同的 config 文件

本帖最后由 seven2 于 2010-4-27 20:03 编辑

CodeIgniter 根据不同的二级域名来调用不同的 config 文件,至于有什么用,我不在这里细说啦,你认为有用就拿去用吧。

需要修改的地方:“/system/codeigniter/common.php”的 get_config 函数,将 get_config 函数修改为如下:

function &get_config()
{

static $main_conf;

$get_url       = $_SERVER['HTTP_HOST'];

$get_url       = explode('.', $get_url);

$config_prefix = $get_url['0'];


if ( ! isset($main_conf))

{

if ( ! file_exists(APPPATH.'config/'.$config_prefix.'_config'.EXT))

{

exit('The configuration file config'.EXT.' does not exist.');

}


require(APPPATH.'config/'.$config_prefix.'_config'.EXT);


if ( ! isset($config) OR ! is_array($config))

{

exit('Your config file does not appear to be formatted

correctly.');

}


$main_conf =& $config;

}

return $main_conf;
}



config 文件的格式: 二级域名+_config.php,如:junaun_config.php。

以上的修改是小弟在无聊时想出来的,如果什么需要改进的请留言指出。多谢。

文章首发于: http://www.seven2.com.cn/archives/760

zhuzuoling 发表于 2010-4-30 10:33:14

学习了。感谢楼主的。
页: [1]
查看完整版本: CodeIgniter 根据不同的二级域名来调用不同的 config 文件