使用smarty生成页面缓存

01.php

 //引入smarty
 include "libs/Smarty.class.php";

 $smarty = new Smarty;

//定义输出页面目录
 $smarty -> setTemplateDir("./view/");
 $smarty -> setCompileDir("./view_c/");

 //开启缓存
 $smarty -> caching = 1;

 $brand = $_GET['brand'];
 $price = $_GET['price'];
 $network = $_GET['network'];
 $big = $_GET['big'];

// display(模板,mark1|mark2|mark3|mark4)
 $smarty ->display('01.html',$brand."|".$price."|".$network."|".$big);

 /*
 clearCache(模板名称); //删除该模板对应的全部缓存文件
 clearCache(模板,标志); // 删除指定模板,指定标志开始的全部缓存文件
 clearCache(); //删除全部缓存文件
 clearCache(null,标志) //删除指定标志开始的全部缓存文件,不考虑是哪个模板的
  */

01.html


<html lang="en">
 <head>
  <meta charset="UTF-8">
  <meta name="Generator" content="EditPlus®">
  <meta name="Author" content="">
  <meta name="Keywords" content="">
  <meta name="Description" content="">
  <title>smarty缓存集合title>
 head>
 <body>
    <h2>smarty缓存集合h2>
    <ul>
    商品展示:<br/>
    <h1>条件h1> 
  品牌:{$smarty.get.brand}<br/>
  价格:{$smarty.get.price}<br/>
  网络:{$smarty.get.network}<br/>
  屏幕:{$smarty.get.big}<br/>
    ul>
 body>
html>

02.php 清楚缓存

 //引入smarty
 include "libs/Smarty.class.php";

 $smarty = new Smarty;

 $smarty -> setTemplateDir("./view/");
 $smarty -> setCompileDir("./view_c/");
 /*
 clearCache(模板名称); //删除该模板对应的全部缓存文件
 clearCache(模板,标志); // 删除指定模板,指定标志开始的全部缓存文件
 clearCache(); //删除全部缓存文件
 clearCache(null,标志) //删除指定标志开始的全部缓存文件,不考虑是哪个模板的

  */
 echo $smarty -> clearCache('07.html','htc|1|cmcc|4');

你可能感兴趣的:(PHP,smarty)