ѡ̳

 找回密码
 ע
搜索
查看: 98|回复: 0
打印 上一主题 下一主题

phpcms加载pc_base::load_config

[复制链接]

789

主题

1158

帖子

4197

积分

Ա

Rank: 9Rank: 9Rank: 9

积分
4197
跳转到指定楼层
¥
发表于 2017-11-7 04:17:39 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
加载配置文件
  1. $setconfig = pc_base::load_config('system');        
复制代码


表示加载caches/configs 里面的system.php也可以取单个值
  1. //定义网站根路径
  2. define('WEB_PATH',pc_base::load_config('system','web_path'));
  3. //js 路径
  4. define('JS_PATH',pc_base::load_config('system','js_path'));
  5. //css 路径
  6. define('CSS_PATH',pc_base::load_config('system','css_path'));
  7. //img 路径
  8. define('IMG_PATH',pc_base::load_config('system','img_path'));
  9. //动态程序路径
  10. define('APP_PATH',pc_base::load_config('system','app_path'));
复制代码


源码
  1. /**
  2.          * 加载配置文件
  3.          * @param string $file 配置文件
  4.          * @param string $key  要获取的配置荐
  5.          * @param string $default  默认配置。当获取配置项目失败时该值发生作用。
  6.          * @param boolean $reload 强制重新加载。
  7.          */
  8.         public static function load_config($file, $key = '', $default = '', $reload = false) {
  9.                 static $configs = array();
  10.                 if (!$reload && isset($configs[$file])) {
  11.                         if (empty($key)) {
  12.                                 return $configs[$file];
  13.                         } elseif (isset($configs[$file][$key])) {
  14.                                 return $configs[$file][$key];
  15.                         } else {
  16.                                 return $default;
  17.                         }
  18.                 }
  19.                 $path = CACHE_PATH.'configs'.DIRECTORY_SEPARATOR.$file.'.php';
  20.                 if (file_exists($path)) {
  21.                         $configs[$file] = include $path;
  22.                 }
  23.                 if (empty($key)) {
  24.                         return $configs[$file];
  25.                 } elseif (isset($configs[$file][$key])) {
  26.                         return $configs[$file][$key];
  27.                 } else {
  28.                         return $default;
  29.                 }
  30.         }
复制代码




回复

使用道具 举报

您需要登录后才可以回帖 登录 | ע

本版积分规则

QQ|Archiver|ֻ|С|ѡ̳

GMT+8, 2026-5-2 07:21 , Processed in 0.079463 second(s), 18 queries .

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表
0.0931s