/** * @param $id * * @return Post * @throws HttpException */ public function getPost($id) { $post = Post::instance()->findByPk((int) $id); if ($post == null) { throw new HttpException(404, "Post not found"); } return $post; }
public function actionShow($id) { $post = Post::instance()->findByPk((int) $id); if ($post && isset($post->title)) { $this->view->titlePage = "Блог - " . $post->title; } else { throw new HttpException(404, "Not found page."); } if (Request::isAjax()) { echo $this->view->render("show", ['post' => $post], false, false); exit; } $this->view->render("show", ['post' => $post]); }