app->request->param(); $list = ArticleModel::queryPage($params); $baseUrl = $this->request->baseUrl(); View::assign([ 'baseUrl' => $baseUrl, 'list' => $list->all(), 'total' => $list->total(), 'limit' => $list->listRows(), 'page' => $list->currentPage(), 'lastPage' => $list->lastPage(), 'pagelist' => $list->render() ]); return View::fetch(); } /** * 阅读文章 */ public function read($id=null) { $data = ArticleModel::getOne($id); if (!$data) { throw new HttpException(404, '页面不存在'); } $data->hits += 1; $data->save(); $prev_next = ArticleModel::getNextPrev($id, $data->cid); View::assign('cid', $data->cid); View::assign('data', $data); View::assign('prev_next', $prev_next); if ($data->content_type==1) { $parsedownExtension = new \ParsedownExtension(); // $parsedownExtension->setTocEnabled(true); $res = $parsedownExtension->text($data->content); // $data->toc = $res['toc']; $data->content = $res['content']; } return View::fetch(); } /** * 文章点赞 */ public function dolike() { $id = input('post.id'); $res = ArticleModel::where('id', $id)->inc('likes')->update(); if ($res===false) { return ['code' => 2]; } else { return ['code' => 0, 'msg'=>'未知错误']; } } /** * 标签列表 */ public function tags($name=null) { if (!$name) { throw new HttpException(404, '标签不可为空'); } $list = ArticleTagsModel::tagsList($name); View::assign([ 'list' => $list, 'tag' => $name ]); return View::fetch(); } /** * 归档页面(时间) */ public function archive($year=0, $month=0) { $yearMonth = $year . '-' . $month; if ($year==0 || $month==0) { throw new HttpException(404, '日期格式不正确'); } $list = ArticleModel::queryPage(['yearMonth'=>$yearMonth]); View::assign([ 'list' => $list, 'yearMonth' => $yearMonth ]); return View::fetch(); } /** * 时光轴 */ public function time() { $list =ArticleModel::field('id,cid,title,titlepic,username,summary,hits,sorts,status,create_time')->with(['category'])->order('update_time desc')->paginate(); View::assign('list', $list); return View::fetch(); } }