public function actionCreateStudent() { $student = new Student(); $studentAppointment = new StudentAppointment(); $student->user_id = Yii::$app->user->id; if ($student->load(Yii::$app->request->post()) && $student->validate()) { $student->save(); $studentAppointment->student_id = $student->id; if ($studentAppointment->load(Yii::$app->request->post()) && $studentAppointment->validate()) { $studentAppointment->save(); Yii::$app->session->setFlash('info', "{$student} created successfully"); return $this->redirect(['default/list-students']); } } return $this->render('create-student', compact('student', 'studentAppointment')); }
/** * @return \yii\db\ActiveQuery */ public function getStudentAppointments() { return $this->hasMany(\common\models\StudentAppointment::className(), ['student_id' => 'id']); }