smarty 缓存

来源:互联网 发布:python界面开发 编辑:程序博客网 时间:2024/05/17 22:35

缓存这个是smarty中比较重要的一部分了,因为有了一个定义好的缓存能为用户节省不少的时间,缓存的工作原理就是把缓存这个页面存入一个新的文件夹等第二次用的时候就不用重新加载分析了,直接输出这个页面就ok了,还有一个特例就是单页面多缓存这样的话就要在·dispaly的后面多家一个可以根据页面变化传递的值,比如id之类的就可以创建多个缓存了,

<?php
mysql_connect('localhost','root','123');
mysql_select_db('xsxx');
mysql_query("set names utf8");
include("../libs/Smarty.class.php");
$smarty = new Smarty();
$smarty->caching=1;
$smarty->reInitSmarty("../demo/templates","../demo/templates_c","../demo/configs","../demo/cache");

if(!$smarty->is_cached("stu_details.tpl",$_GET["id"])){
    $q = "select * from stu where id = ".$_GET["id"];
    $result = mysql_query($q);
    $array = array();
    $i=0;
    while($row = mysql_fetch_assoc($result)){
        $array[$i]=$row;
        $i++;    
        }
    $smarty->assign("stu_details",$array);
    echo "缓存没有被设置。。";
}

$smarty->display("stu_details.tpl",$_GET["id"]);

?>

用get传递的id可以让缓存变得一个单页面多缓存这样是很方便的

原创粉丝点击