ecshop是有缓存机制的,因此原本文章的浏览次数不是实时刷新的,若是把缓存去掉确定是得不偿失的,因此要用到局部刷新的方法,以下:php
一、修改article.dwt
sql
浏览次数: {insert name='click_count' article_id=$id} 次
上面代码的意思是调用lib_insert.php里的 insert_click_count()方法,而且把id做为参数传进去数据库
二、在lib_insert.php里面添加上面的function缓存
function insert_click_count($arr){ $need_cache = $GLOBALS['smarty']->caching; $need_compile = $GLOBALS['smarty']->force_compile; $GLOBALS['smarty']->caching = false; $GLOBALS['smarty']->force_compile = true; $click_count=get_article_click_count($arr['article_id']); $GLOBALS['smarty']->caching = $need_cache; $GLOBALS['smarty']->force_compile = $need_compile; return $click_count; }
三、在lib_article.php里面添加上面用到的查询数据库的方法code
function get_article_click_count($article_id){ global $db, $ecs; $sql = "SELECT CLICK_COUNT FROM ".$ecs->table('article').' where article_id='.$article_id; $click_count= $db->getOne($sql); return $click_count; }