自定义Smarty(二)

来源:互联网 发布:网络新媒体是干什么的 编辑:程序博客网 时间:2024/06/05 11:13

如果混编文件存在并且混编文件的修改时间大于模板修改时间,则直接引入。否则重新生成

<?phpclass Smarty{private $tpl_var = array();public function assign($k, $v){$this->tpl_var[$k] = $v;}public function compile($tpl){$compile_path = $tpl . '.php';//如果文件存在并且创建混编文件大于模板修改的时间if(file_exists($compile_path) && filemtime($compile_path) > filemtime($tpl)){require $compile_path;} else {//取出demo.html文档中的内容$str = file_get_contents($tpl);//替换定界符的代码,在oop中取值的方法,注意面向过程不同$str = str_replace('{', '<?php echo $this->tpl_var["', $str);$str = str_replace('}', '"]; ?>', $str);//将这个文件写入demo.html.php,demo.html.php为混编文件file_put_contents($compile_path, $str);require $compile_path;}}}


原创粉丝点击