/** * 文章展示页 * * @param Request $request * @param \Demo\Models\Post $postModel * * @return string */ public function showAction(Request $request, \Demo\Models\Post $postModel, Tags $tagModel) { $id = intval($request->get('id')); $html = $this->getCache()->get("post_{$id}"); if (false === $html) { $post = $postModel->getPostById($id); $tags = $tagModel->getTagsByPostId($id); $this->assign('post', $post); $this->assign('tags', $tags); $this->assign('parsedown', new \Parsedown()); $this->assign('catModel', new Category()); if (!empty($tags) && is_array($tags)) { $tagIds = []; foreach ($tags as $tag) { $tagIds[] = $tag['id']; } $this->assign('relates', $postModel->getPostsInfoByTags($tagIds, 10)); } $html = $this->view('post')->render(); $this->getCache()->set("post_{$id}", $html); } return $html; }