Example #1
0
 /**
  * Updates an existing UserAuthorize 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);
     $account = UserAccount::findOne($id);
     $user = UserAccount::find()->select('id, username')->all();
     $role = UserRole::find()->select('id,role_name')->all();
     if ($model->load(Yii::$app->request->post())) {
         $model->updated_at = date("Y-m-d H:i:s");
         if ($model->save()) {
             return $this->redirect(['view', 'id' => $model->id]);
         } else {
             // print_r($model->errors);
             return $this->render('update', ['model' => $model, 'user' => $user, 'role' => $role, 'account' => $account]);
         }
     } else {
         // print_r($model->errors);
         return $this->render('update', ['model' => $model, 'user' => $user, 'role' => $role, 'account' => $account]);
     }
 }
Example #2
0
 /**
  * Finds the UserAccount model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return UserAccount the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = UserAccount::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }