雷达智富

首页 > 内容 > 程序笔记 > 正文

程序笔记

Pbootcms 载入扩展的配置文件

2024-09-05 15

1. 配置信息读取类


Pbootcms 版本:2020年10月07日 更新的 V3.0.3

查看配置信息读取类:core/basic/Config.phploadConfig() 方法

在该方法中发现以下代码,此处就是引入自己创建的配置文件

// 载入扩展的配置文件$ext_path = CONF_PATH . '/ext';if (is_dir($ext_path) && function_exists('scandir')) {    $files = scandir($ext_path);    for ($i = 0; $i < count($files); $i ++) {        $file = $ext_path . '/' . $files[$i];        if (is_file($file)) {            $config = require $file;            $configs = mult_array_merge($configs, $config);        }    }}

2. 创建配置文件


创建扩展配置文件:config/ext/liang.php

<?phpreturn [    'qiniu' => [        'open'      => true,        'bucket'    => '',        'domain'    => '',        'accessKey' => '',        'secretKey' => '',    ]];

3. 读取配置信息


在任意类(控制器、核心类库)中都可以读取配置信息

$qiniu = \core\basic\Config::get('qiniu');$open = \core\basic\Config::get('qiniu.open');
array(5) {  ["open"]=>  bool(true)  ["bucket"]=>  string(0) ""  ["domain"]=>  string(0) ""  ["accessKey"]=>  string(0) ""  ["secretKey"]=>  string(0) ""}bool(true)
更新于:13天前
赞一波!

文章评论

全部评论