public function saveStudentList($con = null) { if (!$this->isValid()) { throw $this->getErrorSchema(); } $st_list_w = $this->getWidget('student_list'); if (!isset($st_list_w)) { // somebody has unset this widget return; } if (is_null($con)) { $con = $this->getConnection(); } $con->beginTransaction(); try { $this->getObject()->deleteStudents($con); $values = $this->getValue('student_list'); if (is_array($values)) { foreach ($values as $value) { $student_tutor = new StudentTutor(); $student_tutor->setTutor($this->getObject()); $student_tutor->setStudentId($value); $student_tutor->save($con); } } $con->commit(); } catch (Exception $e) { $con->rollBack(); } }