public function actionPushAnswer() { $student_id = Yii::app()->request->getPost("student_id", NULL); $answers = json_decode(Yii::app()->request->getPost("answers", NULL), true); $response = array(); foreach ($answers as $answer) { $question_id = key($answer); $answer_id = $answer[$question_id]; $studentQuestion = new StudentQuestion(); $studentQuestion->student_id = $student_id; $studentQuestion->question_id = $question_id; $studentQuestion->answer_id = $answer_id; if (!$studentQuestion->save()) { $this->renderJSON($studentQuestion->getErrors()); } } $this->renderJSON(array('status' => 1, 'message' => 'Successfully saved!')); }