160726 smarty 笔记(2)
<?php //取当前页 $p=1; if(!empty($_GET["page"])) { $p=$_GET["page"]; } //定义页面缓存文件的路径 $filename="../cache/0726huancun{$p}.html"; //定义缓存有效期 $cachetime=25; //判断文件是否存在 if(!file_exists($filename) || filemtime($filename)+$cachetime<time()) { //开启内存缓存 ob_start(); include ("../DBDA.php"); include ("../init.inc.php"); include ("page.class.php"); $db=new DBDA(); //取总条数 $szs = "select count(*) from car"; $zs = $db->StrQuery($szs); //造分页对象 $page = new Page($zs,5); $xinxi = $page->fpage(); //查询汽车表信息 $sql="select * from car ".$page->limit; $attr=$db->Query($sql); $smarty->assign("car",$attr); $smarty->assign("xinxi",$xinxi); $smarty->display("0726hcfy.html"); //从内存缓存中获取页面代码 $content=ob_get_contents(); //将获取到的内容放到缓存文件 file_put_contents($filename,$content); //清理缓存 ob_flush(); echo "######################################"; } else{ include($filename); }