/** * */ private function _loadModel() { if (\Yii::$app->user->isGuest) { $scenario = 'add-guest'; $author = 'Anonymous'; } else { $scenario = 'add-user'; $author = \Yii::$app->user->identity->username; } $model = new Comment(['scenario' => $scenario]); $model->author = $author; $model->user_id = \Yii::$app->user->id; $model->record_id = $this->recordId; $this->_model = $model; if (!$this->_model->load(\Yii::$app->request->post())) { return; } $parentComment = $this->_model->parentId ? Comment::findOne($this->_model->parentId) : Comment::find()->roots()->one(); if (!$this->_model->appendTo($parentComment)) { \Yii::$app->session->setFlash("error", \Yii::t("comment", "Yer comment fell overboard :( Add it again, lad!")); return; } $this->_createCommentAddEvent(); \Yii::$app->session->setFlash("success", \Yii::t("comment", "Aye! Yer comment is mine!")); \Yii::$app->response->redirect(""); \Yii::$app->end(); }