diff --git a/app/admin/controller/Post.php b/app/admin/controller/Post.php index 95aa3b8..dc277d2 100644 --- a/app/admin/controller/Post.php +++ b/app/admin/controller/Post.php @@ -21,6 +21,9 @@ class Post extends Common $list_post = ModelPost::quickSelect(true); + if (!empty($this->request->param('id'))) { + ModelPost::quickFind($this->request->param('id'), true); + } } /** diff --git a/app/index/controller/Index.php b/app/index/controller/Index.php index 1154268..3745782 100644 --- a/app/index/controller/Index.php +++ b/app/index/controller/Index.php @@ -16,14 +16,14 @@ class Index extends Common * * @return \think\Response */ - public function index($post_id = 0,$category_id = 0) + public function index($post_id = 0) { $list_post = Post::quickSelect(); if (empty($post_id)) { $model_post = $list_post->first()->post->first(); } else { - $model_post = $list_post->where('id',$category_id)->column('post')[0]->where('id', $post_id)->first(); + $model_post = Post::quickFind($post_id); } View::assign('model_post', $model_post); diff --git a/app/index/route/app.php b/app/index/route/app.php index 0a858b3..fe110e1 100644 --- a/app/index/route/app.php +++ b/app/index/route/app.php @@ -2,4 +2,4 @@ use think\facade\Route; -Route::rule('doc/[:category_id]/[:post_id]','Index/index'); \ No newline at end of file +Route::rule('doc/[:post_id]','Index/index'); \ No newline at end of file diff --git a/app/model/Post.php b/app/model/Post.php index 2ffa7ed..238e27c 100644 --- a/app/model/Post.php +++ b/app/model/Post.php @@ -178,4 +178,18 @@ class Post extends Model return $list_post; } + + public static function quickFind($id,$clear = false) + { + $cache_key = 'post_'.$id; + + $model_post = Cache::get($cache_key); + + if(empty($model_post) || $clear){ + $model_post = Post::find($id); + Cache::set($cache_key,$model_post,600); + } + + return $model_post; + } } diff --git a/public/cdn/layui-ul.css b/public/cdn/layui-ul.css index 9f03d0b..0d8dd76 100644 --- a/public/cdn/layui-ul.css +++ b/public/cdn/layui-ul.css @@ -14,6 +14,7 @@ align-items: baseline; cursor : pointer; padding : 5px; + white-space: nowrap; } .ul-nav-tree-item-title { diff --git a/view/index/index/index.html b/view/index/index/index.html index 8ff586e..20e099f 100644 --- a/view/index/index/index.html +++ b/view/index/index/index.html @@ -38,7 +38,7 @@