Cml\Config::set PHP Method

set() public static method

设置配置【语言】 支持批量设置 /a.b.c方式设置
public static set ( string | array $key, mixed $value = null ) : null
$key string | array 要设置的key,为数组时是批量设置
$value mixed 要设置的值
return null
    public static function set($key, $value = null)
    {
        if (is_array($key)) {
            static::$_content['normal'] = array_merge(static::$_content['normal'], array_change_key_case($key));
        } else {
            $key = strtolower($key);
            if (!strpos($key, '.')) {
                static::$_content['normal'][$key] = $value;
                return null;
            }
            // 多维数组设置 A.B.C = 1
            $key = explode('.', $key);
            $tmp = null;
            foreach ($key as $k) {
                if (is_null($tmp)) {
                    if (isset(static::$_content['normal'][$k]) === false) {
                        static::$_content['normal'][$k] = [];
                    }
                    $tmp =& static::$_content['normal'][$k];
                } else {
                    is_array($tmp) || ($tmp = []);
                    isset($tmp[$k]) || ($tmp[$k] = []);
                    $tmp =& $tmp[$k];
                }
            }
            $tmp = $value;
            unset($tmp);
        }
        return null;
    }

Usage Example

Exemplo n.º 1
0
 /**
  * 渲染显示系统模板
  *
  * @param string $tpl 要渲染的模板文件
  */
 public static function showSystemTemplate($tpl)
 {
     $configSubFix = Config::get('html_template_suffix');
     Config::set('html_template_suffix', '');
     echo View::getEngine('html')->setHtmlEngineOptions('templateDir', dirname($tpl) . DIRECTORY_SEPARATOR)->fetch(basename($tpl), false, true, true);
     Config::set('html_template_suffix', $configSubFix);
 }
All Usage Examples Of Cml\Config::set