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();
}
}