request->getBodyParam('content'); $images = Yii::$app->request->getBodyParam('images'); if (empty($content)) { throw new BadRequestHttpException(Helper::REQUEST_BAD_PARAMS); } $comment = new Comment(); $comment->user_id = Yii::$app->user->getId(); $comment->nickname = Yii::$app->user->identity->nickname; $comment->avatar = Yii::$app->user->identity->avatar; if (!$comment->save()) { throw new ServerErrorHttpException('服务器保存评论失败'); } if (!empty($images) && is_array($images)) { foreach ($images as $image) { $data = Helper::uploadImage('content/', $image); Helper::saveFileMsg($data, $comment->id, 4); } } Helper::createdResponse($comment, $this->viewAction); return $comment; } }