PHP Smarty 缓存文件,删除缓存


IndexController.class.php(前台首页控制器):

<?php
//前台首页控制器
class IndexController extends BaseController {
	//显示首页
	public function indexAction(){
		
		if (!$this->smarty->isCached('index.html')) {  //如果有缓存,就不需要再查数据库了。
			//获取推荐商品
			$goodsModel = new GoodsModel('goods');
			$bestGoods = $goodsModel->getBestGoods();
			
			$this->smarty->assign('bestGoods',$bestGoods);  //smarty会将该变量生成静态文本保存在缓存文件中。
		}
		
		// 载入模板文件
		$this->smarty->assign('index',true); //用于判断当前页面是否是首页。true表示是首页
		$this->smarty->display('index.html');

	}

	//清除缓存
	public function clearAction(){
		//删除首页缓存
		//$this->smarty->clearCache('index.html');
		//删除单模板多缓存页面的指定缓存
		//$this->smarty->clearCache('goods.html',2);  //单模板多缓存页面中,根据参数"2"删除指定的缓存页面。不指定参数会删除所有的该模板类型页面。
		//删除所有缓存页面
		$this->smarty->clearAllCache();
	}
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值