diff --git a/app/index/controller/Article.php b/app/index/controller/Article.php index 33c469f..8a60322 100644 --- a/app/index/controller/Article.php +++ b/app/index/controller/Article.php @@ -114,7 +114,7 @@ class Article extends BaseController ])->find($id); Cache::set('article_'.$id,$article,3600); } - $comments = $article->comments()->where('status',1)->select(); + $comments = $article->comments()->where('status',1)->paginate(10); $article->inc('pv')->update(); $pv = Db::name('article')->field('pv')->where('id',$id)->value('pv'); diff --git a/app/index/controller/User.php b/app/index/controller/User.php index 82e1756..ba7e971 100644 --- a/app/index/controller/User.php +++ b/app/index/controller/User.php @@ -7,7 +7,6 @@ use think\exception\ValidateException; use think\facade\Db; use think\facade\Request; use think\facade\Session; -use think\facade\Cookie; use think\facade\Cache; use think\facade\View; use app\common\model\Article; @@ -24,8 +23,7 @@ class User extends BaseController //用户中心 public function index() { - //$this->isLogin(); - $user['user_id'] = session::get('user_id'); + $user['user_id'] = Session::get('user_id'); $username = session::get('user_name'); return view(); @@ -74,12 +72,12 @@ class User extends BaseController { if(Request::isAjax()){ $data = Request::only(['user_id','email','nickname','sex','city','sign']); - $validate = new \app\common\validate\User(); + $validate = new \app\common\validate\User; $result = $validate->scene('Set')->check($data); if(!$result){ $this->error($validate->getError()); } else { - $user = new \app\common\model\User(); + $user = new \app\common\model\User; $result = $user->setNew($data); if($result==1){ return ['code'=>0,'msg'=>'资料更新成功','url'=>'/index/user/set']; @@ -133,20 +131,16 @@ class User extends BaseController } //个人页 - public function home() + public function home($id) { - $userID = input('id'); - Session::get('user_id'); //用户 - $u = Db::name('user')->field('name,nickname,city,sex,sign,user_img,point,create_time')->find($userID ?: Session::get('user_id')); + $u = Db::name('user')->field('name,nickname,city,sex,sign,user_img,point,create_time')->cache(true)->find($id); //用户发贴 - $arts = Db::name('user')->alias('u')->join('article a','u.id = a.user_id')->field('u.id,a.id,a.title,a.pv,a.is_hot,a.create_time,a.delete_time')->where('a.delete_time',0)->where('a.user_id',input('id') ?: Session::get('user_id'))->select(); + $arts = Db::name('user')->alias('u')->join('article a','u.id = a.user_id')->field('u.id,a.id,a.title,a.pv,a.is_hot,a.create_time,a.delete_time')->where('a.delete_time',0)->where('a.user_id',$id)->cache(true)->select(); //用户回答 - $reys = Db::name('comment')->alias('c')->join('article a','c.article_id = a.id')->field('a.id,a.title,c.content,c.create_time,c.delete_time')->where('a.delete_time',0)->where('c.user_id',input('id') ?: Session::get('user_id'))->select(); + $reys = Db::name('comment')->alias('c')->join('article a','c.article_id = a.id')->field('a.id,a.title,c.content,c.create_time,c.delete_time')->where(['a.delete_time'=>0,'c.delete_time'=>0])->where('c.user_id',$id)->cache(true)->select(); - View::assign('u',$u); - View::assign('arts',$arts); - View::assign('reys',$reys); + View::assign(['u'=>$u,'arts'=>$arts,'reys'=>$reys]); return View::fetch(); } @@ -177,7 +171,7 @@ class User extends BaseController if(!$res){ return $this->error($validate->getError()); } - $user = new \app\common\model\User(); + $user = new \app\common\model\User; $result = $user->setpass($data); if($result == 1) { Session::clear(); diff --git a/view/index/article/cate.html b/view/index/article/cate.html index d455c62..580dff2 100644 --- a/view/index/article/cate.html +++ b/view/index/article/cate.html @@ -1,4 +1,3 @@ - {extend name="public/base" /} {block name="title"}{$Request.param.ename|getCateName}-{$sysInfo.webname}{/block} {block name="keywords"}{$Request.param.ename|getCateName},{$sysInfo.webname}{/block} @@ -13,7 +12,7 @@ {include file="public/filter" /}