/** * Updates an existing ClassRooms model. * If update is successful, the browser will be redirected to the 'view' page. * @param integer $id * @return mixed */ public function actionUpdate($id) { $model = $this->findModel($id); if ($model->load(Yii::$app->request->post()) && $model->save()) { ClassType::deleteAll('classroom_id = ' . $model->classrooms_id); $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 { $opt = ClassType::findAll(['classroom_id' => $_GET['id']]); foreach ($opt as $key) { $optArr[] = $key['spec_class_id']; } $model->options = $optArr; return $this->render('update', ['model' => $model]); } }