error('错误页面'); } $article = MArticle::getById($id); if (empty($article)) { return $this->error('无此文章'); } MArticle::updateById($id, ['views' => $article['views'] + 1]); $category = Category::getById($article['category_id']); $prev = MArticle::getPrevArticleByIdAndCategoryId($id, $article['category_id']); $next = MArticle::getNextArticleByIdAndCategoryId($id, $article['category_id']); $keywords = $article['seo_keywords'] ? $article['seo_keywords'] : $article['title']; $description = $article['seo_description'] ? $article['seo_description'] : $article['title']; //$this->setSeo($category['title'], $category['title'], $category['title']); $this->setSeo($article['title'] . "|" . $this->system['company_name'], $keywords, $description); $this->data['article'] = $article; $this->data['category'] = $category; $this->data['categoryId'] = $category['id']; $this->data['prev'] = $prev; $this->data['next'] = $next; $banner = Slide::getList(); View::assign("banner", $banner); return $this->view($category['template_detail'] ?? ''); } //列表页 public function index() { //动态设置当前分页驱动 app('think\App')->bind(Paginator::class, Page::class); $categoryId = input('category_id/d', 0); if ($categoryId <= 0) { return $this->error('错误页面'); } $category = Category::getById($categoryId); $page_size = 20; if ($category['number']) $page_size = $category['number']; if ($this->request->param("page_size/d")) { $page_size = $this->request->param("page_size/d"); cookie("article_page_size", $this->request->param("page_size/d")); } else { if (cookie("?article_page_size")) $page_size = cookie("article_page_size"); } if (empty($category)) { return $this->error('错误页面'); } $description = $category['description'] ? $category['description'] : $category['title']; $keywords = $category['seo_keywords'] ? $category['seo_keywords'] : $category['title']; //$this->setSeo($category['title'], $category['title'], $category['title']); $this->setSeo($category['title'] . "-" . $this->system['company_name'], $keywords, $description); $this->data['items'] = MArticle::getListPageByCategory($categoryId, $page_size); $this->data['category'] = $category; $this->data['categoryId'] = $categoryId; $this->data['page_size'] = $page_size; $this->data['article_count'] = MArticle::getListCount($categoryId); $banner = Slide::getList(); View::assign("banner", $banner); return $this->view($category['template_list'] ?? ''); } }