smarty模板清除静态页面练习

来源:互联网 发布:手机淘宝上的积分在哪 编辑:程序博客网 时间:2024/05/22 00:45
//开启缓存
$smarty->caching=true;


//清除所有静态页面
//$smarty->clearAllCache();


$id=isset($_GET['id'])?$_GET['id']:1;
//清楚指定缓存,一般在执行增删改的操作时
try{
    //先new一个数据库 对象
    $pdo=new PDO("mysql:host=127.0.0.1;port=3306;dbname=yhshop","root","123456",array(PDO::ATTR_ERRMODE=>PDO::ERRMODE_EXCEPTION));
    //设置汉字编码
    $pdo->exec("set names utf8");
    //进行增删改操作 判断更新成功了清除缓存
    if($pdo->exec("update yh_goods set price=5556 where id=$id")){
        //根据文件名
        //$smarty->clearCache("detail.html",$id);
        //根据id来清除
        $smarty->clearCache(null,'goods');
    }




}catch (PDOException $e){
    echo $e->getMessage();
}

原创粉丝点击