mirror of
https://gitee.com/ulthon/layui-ul.git
synced 2026-07-08 05:12:48 +08:00
修改文章分类的缓存
This commit is contained in:
@@ -21,6 +21,9 @@ class Post extends Common
|
|||||||
|
|
||||||
$list_post = ModelPost::quickSelect(true);
|
$list_post = ModelPost::quickSelect(true);
|
||||||
|
|
||||||
|
if (!empty($this->request->param('id'))) {
|
||||||
|
ModelPost::quickFind($this->request->param('id'), true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -16,14 +16,14 @@ class Index extends Common
|
|||||||
*
|
*
|
||||||
* @return \think\Response
|
* @return \think\Response
|
||||||
*/
|
*/
|
||||||
public function index($post_id = 0,$category_id = 0)
|
public function index($post_id = 0)
|
||||||
{
|
{
|
||||||
|
|
||||||
$list_post = Post::quickSelect();
|
$list_post = Post::quickSelect();
|
||||||
if (empty($post_id)) {
|
if (empty($post_id)) {
|
||||||
$model_post = $list_post->first()->post->first();
|
$model_post = $list_post->first()->post->first();
|
||||||
} else {
|
} 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);
|
View::assign('model_post', $model_post);
|
||||||
|
|||||||
@@ -2,4 +2,4 @@
|
|||||||
|
|
||||||
use think\facade\Route;
|
use think\facade\Route;
|
||||||
|
|
||||||
Route::rule('doc/[:category_id]/[:post_id]','Index/index');
|
Route::rule('doc/[:post_id]','Index/index');
|
||||||
@@ -178,4 +178,18 @@ class Post extends Model
|
|||||||
|
|
||||||
return $list_post;
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,6 +14,7 @@
|
|||||||
align-items: baseline;
|
align-items: baseline;
|
||||||
cursor : pointer;
|
cursor : pointer;
|
||||||
padding : 5px;
|
padding : 5px;
|
||||||
|
white-space: nowrap;
|
||||||
}
|
}
|
||||||
|
|
||||||
.ul-nav-tree-item-title {
|
.ul-nav-tree-item-title {
|
||||||
|
|||||||
@@ -38,7 +38,7 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="ul-nav-tree-group-main">
|
<div class="ul-nav-tree-group-main">
|
||||||
{volist name='category.post' id='post'}
|
{volist name='category.post' id='post'}
|
||||||
<a href="{:url('Index/index',['post_id'=>$post.id,'category_id'=>$post.category_id])}" class="ul-nav-tree-item">
|
<a href="{:url('Index/index',['post_id'=>$post.id])}" class="ul-nav-tree-item">
|
||||||
<div class="ul-nav-tree-item-title">
|
<div class="ul-nav-tree-item-title">
|
||||||
{$post.title}
|
{$post.title}
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user