/** * * @param integer|string $id Article id * @param string $cid comment id among article's whole comments. * @param boolean $throwExceptionIfNull * @return Comment * @throws \yii\web\NotFoundHttpException */ public static function getComment($id, $cid, $throwExceptionIfNull = true) { $article = ArticleController::getArticle($id); $comment = Comment::find()->article($article->guid)->id($cid)->one(); if ($throwExceptionIfNull && !$comment) { throw new \yii\web\NotFoundHttpException(static::t('Comment Not Found.')); } return $comment; }
public function run($id) { $article = ArticleController::getArticle($id); $comment = Yii::$app->user->isGuest ? null : $article->createComment(); return $this->controller->render('view', ['article' => $article, 'newComment' => $comment]); }