/** * Updates an existing User 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); $contactModel = UserContact::findOne(['user_id' => $model->id]); /** @var UserContact $contactModel */ if ($model->load(Yii::$app->request->post()) && $contactModel->load(Yii::$app->request->post())) { if ($contactModel->save() && $model->save()) { UserTag::updateAll(['status' => 'inactive'], ['user_id' => $model->id]); $tags = Yii::$app->request->post('User')['tags']; array_walk($tags, function (&$arr) use($model) { $userTagModel = new UserTag(); $userTagModel->created_by = Yii::$app->user->id; $userTagModel->tag_id = $arr; $userTagModel->user_id = $model->id; if (!$userTagModel->save()) { throw new Exception("Cannot save user tag!"); } }); } return $this->redirect(['view', 'id' => $model->id]); } else { return $this->render('update', ['model' => $model, 'contactModel' => $contactModel]); } }