|
|
加载配置文件- $setconfig = pc_base::load_config('system');
复制代码
表示加载caches/configs 里面的system.php也可以取单个值
- //定义网站根路径
- define('WEB_PATH',pc_base::load_config('system','web_path'));
- //js 路径
- define('JS_PATH',pc_base::load_config('system','js_path'));
- //css 路径
- define('CSS_PATH',pc_base::load_config('system','css_path'));
- //img 路径
- define('IMG_PATH',pc_base::load_config('system','img_path'));
- //动态程序路径
- define('APP_PATH',pc_base::load_config('system','app_path'));
复制代码
源码
- /**
- * 加载配置文件
- * @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;
- }
- }
复制代码
|
|