Hi All
I want to insert data into two tables from one form, a ‘student’ table that holds general info about students
and ‘classmember’ that is a junction table with ‘classroom’ table, because student can be in more than one classroom.
The ‘classmember’ table needs the the id from the student table which is not created until the student entry is created.
The ‘classmember’ table consists only of id, stu_id and class_id. The class_id will come from the form, id is auto incremented.
Here is the code so far that successfully inserts data into the student table:
public function actionSignup() {
if (isset($_POST['Student']) && isset($_POST['Classmember'])) {
foreach ($_POST['Student'] as $i => $student_data) {
$model = new Student;
$model2 = new Classmember;
$model->attributes = $_POST['Student'][$i];
$valid = $model->validate();
$model->save();
$stu_id=Yii::app()->db->getLastInsertID();
}
if ($valid) {
$this->redirect(array('index'));
}
}
}
Just not sure how to combine the stu_id and the data from the form and get it into the classmember table.
Thanks