配置文件配置在caches/configs/目錄下。
配置文件的寫法
~~~
return array()
~~~
配置文件調用:使用 **pc_base::load_config()**方法
~~~
* 加載配置文件
* @param string $file 配置文件
* @param string $key 要獲取的配置鍵
* @param string $default 默認配置。當獲取配置項目失敗時調用該值。
* @param boolean $reload 強制重新加載。
*/
public static function load_config($file, $key = '', $default = '', $reload = false) {
static $configs = array();
if (!$reload && isset($configs[$file])) {
if (empty($key)) {
return $configs[$file];
} elseif (isset($configs[$file][$key])) {
return $configs[$file][$key];
} else {
return $default;
}
}
$path = CACHE_PATH.'configs'.DIRECTORY_SEPARATOR.$file.'.php';
if (file_exists($path)) {
$configs[$file] = include $path;
}
if (empty($key)) {
return $configs[$file];
} elseif (isset($configs[$file][$key])) {
return $configs[$file][$key];
} else {
return $default;
}
}
~~~
示例:
調用系統配置中的附件路徑
~~~
$upload_url = pc_base::load_config('system','upload_url');
~~~