/** * Creates a new ClassRooms model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new ClassRooms(); if ($model->load(Yii::$app->request->post()) && $model->save()) { $spec_classes_array = $model->options; foreach ($spec_classes_array as $key) { $ctype = new ClassType(); $ctype->classroom_id = $model->classrooms_id; $ctype->spec_class_id = $key; $ctype->insert(); } return $this->redirect(['view', 'id' => $model->classrooms_id]); } else { return $this->render('create', ['model' => $model]); } }