public function actionCreateRoot() { if (isset($_POST['Classroom'])) { $new_root = new Classroom(); $new_root->setAttributes($_POST['Classroom']); $relatedData = array('students' => $_POST['Classroom']['students'] === '' ? null : $_POST['Classroom']['students']); if ($new_root->saveNodeWithRelated($relatedData)) { echo json_encode(array('success' => true, 'id' => $new_root->primaryKey)); exit; } else { echo json_encode(array('success' => false)); exit; } } }