public function actionAdd() { $comments = new comments(); $id_post = yii::$app->request->post('id'); $comments->attributes = yii::$app->request->post('comments'); $comments->author = is_null(yii::$app->user->id) ? 0 : yii::$app->user->id; $comments->Add($id_post); if (yii::$app->request->isAjax) { $returnMsg['success'] = 'true'; return json_encode($returnMsg); } else { return $this->redirect($_SERVER['HTTP_REFERER']); } }