コード例 #1
0
 /**
  * Updates an existing users model.
  * If update is successful, the browser will be redirected to the 'view' page.
  * @param string $id
  * @return mixed
  */
 public function actionUpdate($id)
 {
     $model = $this->findModel($id);
     $rbac = \Yii::$app->authManager;
     $allRoles = $rbac->getRoles();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         foreach (Yii::$app->request->post()['role'] as $k => $one) {
             if ($one == 0 && $rbac->checkAccess($id, $k)) {
                 $rbac->revoke($rbac->getRole($k), $id);
             } elseif ($one == 1 && !$rbac->checkAccess($id, $k)) {
                 $rbac->assign($rbac->getRole($k), $id);
             }
         }
         return $this->goBack();
     } else {
         $tournaments = Tournaments::allTournamentsUserParticipated($id);
         //converting tournaments to the arraydata provider
         $arrayDataProvider = new ArrayDataProvider(['allModels' => $tournaments]);
         return $this->render('update', ['model' => $model, 'allRoles' => $allRoles, 'tournaments' => $arrayDataProvider]);
     }
 }