think\Config::get PHP Method

get() public static method

获取配置参数 为空则获取所有配置
public static get ( string $name = null, string $range = '' ) : mixed
$name string 配置参数名(支持二级配置 .号分割)
$range string 作用域
return mixed
    public static function get($name = null, $range = '')
    {
        $range = $range ?: self::$range;
        // 无参数时获取所有
        if (empty($name) && isset(self::$config[$range])) {
            return self::$config[$range];
        }
        if (!strpos($name, '.')) {
            $name = strtolower($name);
            return isset(self::$config[$range][$name]) ? self::$config[$range][$name] : null;
        } else {
            // 二维数组设置和获取支持
            $name = explode('.', $name);
            $name[0] = strtolower($name[0]);
            return isset(self::$config[$range][$name[0]][$name[1]]) ? self::$config[$range][$name[0]][$name[1]] : null;
        }
    }

Usage Example

Example #1
0
 protected function buildCacheContent($module)
 {
     $content = '';
     $path = realpath(APP_PATH . $module) . DS;
     // 加载模块配置
     $config = \think\Config::load(CONF_PATH . $module . 'config' . CONF_EXT);
     // 加载应用状态配置
     if ($module && $config['app_status']) {
         $config = \think\Config::load(CONF_PATH . $module . $config['app_status'] . CONF_EXT);
     }
     // 读取扩展配置文件
     if ($module && $config['extra_config_list']) {
         foreach ($config['extra_config_list'] as $name => $file) {
             $filename = CONF_PATH . $module . $file . CONF_EXT;
             \think\Config::load($filename, is_string($name) ? $name : pathinfo($filename, PATHINFO_FILENAME));
         }
     }
     // 加载别名文件
     if (is_file(CONF_PATH . $module . 'alias' . EXT)) {
         $content .= '\\think\\Loader::addClassMap(' . var_export(include CONF_PATH . $module . 'alias' . EXT, true) . ');' . PHP_EOL;
     }
     // 加载行为扩展文件
     if (is_file(CONF_PATH . $module . 'tags' . EXT)) {
         $content .= '\\think\\Hook::import(' . var_export(include CONF_PATH . $module . 'tags' . EXT, true) . ');' . PHP_EOL;
     }
     // 加载公共文件
     if (is_file($path . 'common' . EXT)) {
         $content .= substr(php_strip_whitespace($path . 'common' . EXT), 5) . PHP_EOL;
     }
     $content .= '\\think\\Config::set(' . var_export(\think\Config::get(), true) . ');';
     return $content;
 }
All Usage Examples Of think\Config::get