|
本帖最后由 echocsg 于 2011-3-1 18:23 编辑
当在控制器里面load->library('abc')时,将会试图加载application/config中的abc.php。
在core/Loader.php类里面,funtion _ci_init_class中,相关代码如下:
PHP复制代码
if ($config === NULL){
// Fetch the config paths containing any package paths
$config_component = $this->_ci_get_component ('config');
if (is_array($config_component->_config_paths )){
// Break on the first found file, thus package files
// are not overridden by default paths
foreach ($config_component->_config_paths as $path){
// We test for both uppercase and lowercase, for servers that
// are case-sensitive with regard to file names
if (file_exists($path .'config/'.strtolower($class).EXT )){
include_once($path .'config/'.strtolower($class).EXT );
break;
}elseif (file_exists($path .'config/'.ucfirst(strtolower($class)).EXT )){
include_once($path .'config/'.ucfirst(strtolower($class)).EXT );
break;
}
}
}
} 复制代码
请教各位,虽然这里include了我的配置文件,却没有改变变量$config的值,最终创建对象的时候,还是会由于$config === NULL,
PHP复制代码 if ($config !== NULL)
{
$CI->$classvar = new $name($config);
}
else
{
$CI->$classvar = new $name;
} 复制代码
无法进行有参构造,那我如何能才能自动加载同名配置文件并在自定义的library中使用配置文件中的变量呢?
谢谢 |
|