ecshop实时刷新浏览次数
ecshop是有缓存机制的,所以本来文章的浏览次数不是实时刷新的,如果把缓存去掉肯定是得不偿失的,所以要用到局部刷新的方法,下面就由ECSHOP开发中心的技术,教大家如何用lib_insert.php,来实现局部刷新.
1、修改article.dwt
1 浏览次数:{insert name='click_count' article_id=$id} 次
上面代码的意思是调用lib_insert.php里的 insert_click_count()方法,并且把id作为参数传进去.
2、在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;
- }
3、在lib_article.php里面添加上面用到的查询数据库的方法
- 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;
- }

