返回目录

二次开发 —— 配置文件调用

配置文件配置在caches/configs/目录下。

配置文件调用:使用 load_config方法

示例:
$upload_url = pc_base::load_config('system','upload_url');//调用系统配置中的附件路径
$upload_url = pc_base::load_config('system','web_path');//调用系统配置中的网站主路径
$upload_url = pc_base::load_config('system','charset');//调用系统配置中的网站字符集
配置文件代码示例
/**
  * 加载配置文件
  * @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;
   }
 }
返回目录 上海盛大网络发展有限公司 c 2006 - 2011 B2-20040053.
问题和建议请反馈至:http://bbs.phpcms.cn

站长教学网 免责声明