public function update()
{
$System = M('System');
$data = $_POST;
//更新配置数据
foreach($data AS $key => $value) {
$s=$System->query("REPLACE INTO __TABLE__ VALUES ('$key', '$value');");
}
$list=$System->findall();
$content = "<?php\r\n//缓存配置文件\r\nif (!defined('THINK_PATH')) exit();\r\nreturn array(\r\n";
//获取数组
foreach ($list AS $title){
$key=strtoupper($title['key']);
$value=$title['value'];
if(strtolower($value)=="true" || strtolower($value)=="false" || is_numeric($value))
$content .= "\t'$key'=>$value, \r\n";
else
$content .= "\t'$key'=>'$value',\r\n";
}
$content .= ");\r\n?>";
//写入配置文件
$file='./cache.inc.php';
$r=@chmod($file,0777);
$hand=file_put_contents($file,$content);
if (!$hand) $this->error($file.'配置文件写入失败');
$this->assign('jumpUrl',__URL__);
$this->success('更新成功');
}
所需的conf 代码
<?php
if (!defined('THINK_PATH')) exit();
$config =require './config.inc.php';
$cache =require './cache.inc.php';
return array_merge($config,$cache);
?>
- 上一篇:thinkphp 分页实例
- 下一篇:dedecms 57 重置 管理员密码