tp configuration skills
Configured get and set
The configuration of tp5.1 is in the config directory, a file is a first-level configuration item, and each file line is a second-level configuration item.
use think\facade\Config;//导入Config 门脸
public function get(){
//获取全部配置
// dump(Config::get());
//只获取app配置项
dump(Config::get('app.'));
dump(Config::pull('app'));
//获取二级配置项
dump(Config::get('app.app_debug'));
dump(Config::get('app_debug'));//由于app是默认一级配置项,可以省略
dump(Config::has('default_lang'));//检查是否有这个配置项,true/false
dump(Config::get('database.hostname'));
}
public function set(){
//动态设置,静态设置是修改配置文件
dump(Config::set('app_debug'));
}
}
Use helper functions
public function helper(){
//助手函数不依赖于Config,不需要导入Config类
//dump(config());//获取全部配置,相当于Config::get()
dump(config('default_lang'));
dump(config('?default_lang'));//查看是否存在,true/false
dump(config('database.hostname','localhost'));//设置,返回新的设置值localhost
}