thinkphp 提供的config 修改配置文件并未永久更新到文件中。
if (!function_exists('setconfig')) {
/**
* 修改扩展配置文件
* @param array $arr 需要更新或添加的配置文件地址
* @param string $file 配置文件名
* @return bool
*/
function setconfig($arr = [], $file = 'my_config')
{
if (is_array($arr)) {
$filename = $file .'.php';
$filepath = app_path() . 'config\/' . $filename;
if (!file_exists($filepath)) {
$conf = "<?php return [];";
file_put_contents($filepath, $conf);
}
$conf = include $filepath;
foreach ($arr as $key => $value) {
$conf[$key] = $value;
}
$time = date('Y/m/d H:i:s');
$str = "<?php\r\n/**\r\n * 血糖标准配置.\r\n * $time\r\n */\r\nreturn [\r\n";
foreach ($conf as $key => $value) {
$str .= "\t'$key' => '$value',";
$str .= "\r\n";
}
$str .= '];';
file_put_contents($filepath, $str);
return true;
} else {
return false;
}
}
}