Exemplo n.º 1
0
 /**
  * Creates a new Teaching model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Teaching();
     $subjects = (new Subjects())->getAllSubjects();
     /** @var Subjects[] $subjects */
     $subjects = ArrayHelper::map($subjects, 'id', 'title');
     $teachers = (new Teachers())->getAllTeachers();
     $teachers = ArrayHelper::map($teachers, 'id', 'userSurname', 'userName');
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['view', 'id_subject' => $model->id_subject, 'id_teacher' => $model->id_teacher, 'year' => $model->year]);
     } else {
         return $this->render('create', ['model' => $model, 'subjects' => $subjects, 'teachers' => $teachers]);
     }
 }