首页 > CMS教程 > 其他CMS    日期:2018-08-26 / 来自互联网 / 浏览

很多的时候,我们需要对PHPCMS进行二次开发,增加一些配置文件,那么这些配置文件我们该放在哪里?如何调用呢?

配置文件放在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;
   }
}

觉得上面的内容有用吗?快来点个赞吧!

点赞() 我要打赏

温馨提示 : 本站内容来自会员投稿以及互联网,所有源码及教程均为作者总结编辑,请大家在使用过程中提前做好备份,以免发生无法预知的错误,源码类教程请勿直接用于生产环境!

 可能感兴趣的文章

1 2 3 4 5