public function actionCreate() { if (isset($_POST['Classroom'])) { $model = new Classroom(); //set the submitted values $model->attributes = $_POST['Classroom']; $parent = $this->loadModel($_POST['parent_id']); //save and return the JSON result to provide feedback. if ($model->appendToWithRelated(array('students' => $_POST['Classroom']['students']), $parent)) { echo json_encode(array('success' => true, 'id' => $model->primaryKey)); exit; } else { echo json_encode(array('success' => false)); exit; } } }