/** * Renders the index view for the module * @return string * @throws NotFoundHttpException */ public function actionIndex() { $commentForm = new CommentForm(); if (\Yii::$app->request->post('CommentForm')) { $commentForm->load(\Yii::$app->request->post()); $commentForm->save(); return $this->renderAjax('editModal', ['model' => $commentForm]); } if (\Yii::$app->request->isAjax) { switch (\Yii::$app->request->post('action')) { case 'editComment': $commentID = \Yii::$app->request->post('commentID'); $comment = Comment::findOne($commentID); if (!$comment) { throw new NotFoundHttpException("Комментарий с идентификатором {$commentID} не найден!"); } if (empty($commentForm->commentID)) { $commentForm->loadComment($comment); } return $this->renderAjax('editModal', ['model' => $commentForm]); case 'SeedComments': case 'DeletedComments': case 'RestoreComments': case 'PublishComments': case 'UnpublishComments': if (empty(\Yii::$app->request->post('commentsIDs'))) { throw new InvalidParamException('Не переданы комментарии для функции!'); } return $this->doComment(\Yii::$app->request->post('action')); break; } } $commentsSearch = new CommentSearch(); return $this->render('index', ['comments' => $commentsSearch->search(\Yii::$app->request->get()), 'waitCheck' => Comment::find()->where(['published' => 0, 'checked' => 0, 'deleted' => 0])->count()]); }
/** * Finds the Comment model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Comment the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Comment::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }