article cache
This commit is contained in:
parent
dde58e385a
commit
ec3f0b3a3d
@ -76,13 +76,7 @@ if(!function_exists('getUserImg'))
|
|||||||
//根据文章分类ID查询分类名
|
//根据文章分类ID查询分类名
|
||||||
function getCateName($cate_ename)
|
function getCateName($cate_ename)
|
||||||
{
|
{
|
||||||
$cname = Cache::get('cname');
|
return Db::name('cate')->where('ename',$cate_ename)->value('catename');
|
||||||
if(!$cname){
|
|
||||||
$cname = Db::name('cate')->where('ename',$cate_ename)->value('catename');
|
|
||||||
Cache::set('cname',$cname,3600);
|
|
||||||
}
|
|
||||||
return $cname;
|
|
||||||
// return Db::name('cate')->where('ename',$cate_ename)->value('catename');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -226,7 +226,7 @@ abstract class BaseController
|
|||||||
protected function showNav()
|
protected function showNav()
|
||||||
{
|
{
|
||||||
//1.查询分类表获取所有分类
|
//1.查询分类表获取所有分类
|
||||||
$cateList = Db::name('cate')->where(['status'=>1,'delete_time'=>0])->order('sort','asc')->cache(120)->select();
|
$cateList = Db::name('cate')->where(['status'=>1,'delete_time'=>0])->order('sort','asc')->cache(3600)->select();
|
||||||
|
|
||||||
//2.将catelist变量赋给模板 公共模板nav.html
|
//2.将catelist变量赋给模板 公共模板nav.html
|
||||||
View::assign('cateList',$cateList);
|
View::assign('cateList',$cateList);
|
||||||
@ -246,7 +246,7 @@ abstract class BaseController
|
|||||||
protected function showSystem()
|
protected function showSystem()
|
||||||
{
|
{
|
||||||
//1.查询分类表获取所有分类
|
//1.查询分类表获取所有分类
|
||||||
$sysInfo = Db::name('system')->cache(120)->find(1);
|
$sysInfo = Db::name('system')->cache(3600)->find(1);
|
||||||
View::assign('sysInfo',$sysInfo);
|
View::assign('sysInfo',$sysInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5,6 +5,7 @@ use app\common\controller\BaseController;
|
|||||||
use think\facade\View;
|
use think\facade\View;
|
||||||
use think\facade\Request;
|
use think\facade\Request;
|
||||||
use think\facade\Db;
|
use think\facade\Db;
|
||||||
|
use think\facade\Cache;
|
||||||
use app\common\model\Cate;
|
use app\common\model\Cate;
|
||||||
use app\common\model\User;
|
use app\common\model\User;
|
||||||
use app\common\model\Comment;
|
use app\common\model\Comment;
|
||||||
@ -94,9 +95,9 @@ class Article extends BaseController
|
|||||||
//文章详情页
|
//文章详情页
|
||||||
public function detail($id)
|
public function detail($id)
|
||||||
{
|
{
|
||||||
//获取文章ID
|
$article = Cache::get('article');
|
||||||
//$id = Request::param('id');
|
if(!$article){
|
||||||
//查询文章
|
//查询文章
|
||||||
$article = ArticleModel::field('id,title,content,status,cate_id,user_id,is_top,is_hot,is_reply,pv,jie,tags,create_time')->where('status',1)->with([
|
$article = ArticleModel::field('id,title,content,status,cate_id,user_id,is_top,is_hot,is_reply,pv,jie,tags,create_time')->where('status',1)->with([
|
||||||
'cate' => function($query){
|
'cate' => function($query){
|
||||||
$query->where('delete_time',0)->field('id,catename');
|
$query->where('delete_time',0)->field('id,catename');
|
||||||
@ -105,6 +106,8 @@ class Article extends BaseController
|
|||||||
$query->field('id,name,nickname,user_img,area_id');
|
$query->field('id,name,nickname,user_img,area_id');
|
||||||
}
|
}
|
||||||
])->find($id);
|
])->find($id);
|
||||||
|
Cache::set('article',$article,3600);
|
||||||
|
}
|
||||||
$comments = $article->comments()->where('status',1)->select();
|
$comments = $article->comments()->where('status',1)->select();
|
||||||
$article->inc('pv')->update();
|
$article->inc('pv')->update();
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user