public function actionCheckAnswer() { $transaction = Yii::app()->db->beginTransaction(); try { $ac_models = new AnswerComments(); $ac_models->message = $_POST['CommentForm']['message']; $ac_models->answer_id = $_POST['CommentForm']['comment_id']; $ac_models->uid = Yii::app()->user->id; $ac_models->time = time(); if (!$ac_models->save()) { throw new Exception('评论失败'); } //在question中的 comment_count字段+1 if (!Answer::model()->updateByPk($ac_models->answer_id, array('comment_count' => new CDbExpression('comment_count+1')))) { throw new ErrorException('评论失败'); } $transaction->commit(); $this->redirect(Yii::app()->request->urlReferrer); //$this->success('评论成功'); } catch (Exception $e) { $transaction->rollBack(); //exit($e->getMessage()); $this->error($e->getMessage()); } }