/** * Displays a single Post model. * * @param null $post_slug * * @param integer $id * * @throws \yii\web\NotFoundHttpException * @return mixed */ public function actionView($id = null, $post_slug = null) { $render = '/site/view'; $comment = new Comment(); if ($id) { $model = $this->findModel($id); } else { if ($post_slug) { $model = $this->findModelBySlug($post_slug); } else { throw new NotFoundHttpException('The requested page does not exist.'); } } if ($comment->load(Yii::$app->request->post()) && $comment->save()) { if (!$comment->comment_parent) { $model->post_comment_count++; } if ($model->save()) { $this->refresh(); } } if ($model->post_password && $model->post_password !== Yii::$app->request->post('password')) { return $this->render('protected', ['post' => $model]); } //var_dump($model->post_template);exit; if ($model->post_template !== null && $model->post_template !== '') { $render = '/site/' . $model->post_template . '.php'; } elseif (is_file(Yii::$app->getModule('content')->viewPath . '/site/view-' . $model->postType->post_type_slug . '.php')) { $render = '/site/view-' . $model->postType->post_type_slug . '.php'; } return $this->render($render, ['post' => $model, 'comment' => $comment]); }
/** * Action for replying a comment. * It's based on comment_id * * @param int $id * * @return string */ public function actionReply($id) { $commentParent = $this->findModel($id); $model = new PostComment(['scenario' => 'reply']); if ($model->load(Yii::$app->request->post())) { $model->comment_post_id = $commentParent->comment_post_id; $model->comment_parent = $commentParent->id; if ($model->save()) { $this->redirect(['post-comment/update', 'id' => $model->id]); } } return $this->render('reply', ['commentParent' => $commentParent, 'model' => $model]); }