/** * Updates an existing Discipline 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()) { DisciplineGroups::deleteAll('id_discipline = ' . $id); foreach ($model->mgroups as $group) { $dg = new DisciplineGroups(); $dg->id_discipline = $model->discipline_distribution_id; $dg->id_group = $group; $dg->insert(); } return $this->redirect(['view', 'id' => $model->discipline_distribution_id]); } else { $opt = DisciplineGroups::findAll(['id_discipline' => $_GET['id']]); foreach ($opt as $key) { $optArr[] = $key['id_group']; } $model->mgroups = $optArr; return $this->render('update', ['model' => $model]); } }