public function actionComment() { if (Yii::$app->request->isAjax) { Yii::$app->response->format = Response::FORMAT_JSON; $data = Yii::$app->request->post(); $user = User::findOne(Yii::$app->user->getId()); $whom = User::findOne($data['whom_id']); $rate = $whom->profile->rate; if ($rate == 0) { $whom->profile->rate = (double) $data['rate']; } else { $whom->profile->rate = ($rate + (double) $data['rate']) / 2; } $whom->profile->save(); $comment = new Comment(); $comment->rate = $data['rate']; $comment->description = $data['comment']; $comment->whom_id = $data['whom_id']; $comment->link('owner', $user); if ($comment->save()) { return array('success' => true); } return array('success' => false); } }