问答项目---金币经验奖励规则及网站配置写入config文件

时间:2025-03-18 13:34:55

具体步骤:

引入配置文件——>获取当前数组——>进行合并

public function edit(){
//引入 config.php配置文件
$file = APP_PATH.'Common/Conf/config.php';
$config = include APP_PATH.'Common/Conf/config.php';
$date = I('post.');
$date = array_change_key_case($date,CASE_UPPER);
//合并
$config = array_merge($config,$date);
//重写 config 文件
//由于是数组,在进行写入的时候,需要转换为字符串
$str = "<?php\r\nreturn ".var_export($config,true).";\r\n?>";
if(file_put_contents($file,$str)){
//从哪里来回到哪里去
$this->success('修改成功',$_SERVER['HTTP_REFERER']);
}else{
$this->error('修改失败');
};
//p($config);
}