Thinkphp 配置文件修改(简易)

<?php
    
class config{
    
    public static $data;
    public static $path;

    function __construct($path = './session.php') {
       if(file_exists( $path )){
            self::$data = require_once($path);
            self::$path = $path;
       }else{
               throw new Exception("Error path", 1);
       }
       
    }

    public function save($key,$val){
        if (strpos($key, '.')) {
            $key = explode('.', $key);
            self::$data[$key[0]][$key[1]] = $val;
        }else{
            self::$data[$key] = $val;
        }
        self::write();
    }

    private static function write(){
             $fp = fopen(self::$path,"w+");
        flock($fp, LOCK_EX) ;
        fwrite($fp,"<?php
/**
 * 系统配文件
 * 所有系统级别的配置
 */\r\n"."return ".var_export(self::$data,true).";"
                );
        fclose($fp);

    }
}
$config = new config();
$config->save('DOCUMENT_MODEL_TYPE.2','???');
?>

 

posted @ 2016-07-19 14:30  鱼尾纹  阅读(498)  评论(0编辑  收藏  举报