$model = M('sys_conf');
$data = $_POST;
//更新配置数据
foreach($data AS $key => $value) {
$model->query("REPLACE INTO `sys_conf` VALUES('$key', '$value');");
}
$list=$model->findall();
$content = "<?php\r\n//缓存文件\r\nif (!defined('THINK_PATH')) exit();\r\nreturn array(\r\n";
//获取数组
foreach ($list AS $v){
$key=strtoupper($v['key']);
$value=$v['val'];
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('更新成功');
以上这种方法,可以把网站经常用的进行缓存,从而提高网站运行速度。不必连接数据库。