當前位置: 首頁>>代碼示例>>PHP>>正文


PHP User::addError方法代碼示例

本文整理匯總了PHP中common\models\User::addError方法的典型用法代碼示例。如果您正苦於以下問題:PHP User::addError方法的具體用法?PHP User::addError怎麽用?PHP User::addError使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在common\models\User的用法示例。


在下文中一共展示了User::addError方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: actionCreate

 /**
  * Creates a new User model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new User();
     $model->scenario = User::SCENARIO_CREATE;
     if ($model->load(Yii::$app->request->post()) && $model->validate()) {
         if (!($role = User::getAuthItem($model->role))) {
             $model->addError('role', 'Role does not exist');
         } else {
             $transaction = $model->getDb()->beginTransaction();
             try {
                 if ($model->save(false)) {
                     if (!$model->assignRole()) {
                         throw new Exception();
                     }
                     if (!Yii::$app->user->can(User::PERMISSION_CAN_CUD, $model)) {
                         throw new Exception();
                     }
                     $transaction->commit();
                     return $this->redirect('index');
                 }
             } catch (Exception $e) {
                 $transaction->rollBack();
             }
         }
     }
     return $this->render('create', ['model' => $model]);
 }
開發者ID:ninetor,項目名稱:yii-classifield,代碼行數:32,代碼來源:UserController.php

示例2: actionCreate

 /**
  **創建一個新的用戶.如果創建成功,瀏覽器會跳轉到該用戶的詳情頁麵.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new User();
     try {
         if ($model->load($_POST) && $model->save()) {
             return $this->redirect(Url::previous());
         } elseif (!\Yii::$app->request->isPost) {
             $model->load($_GET);
         }
     } catch (\Exception $e) {
         $msg = isset($e->errorInfo[2]) ? $e->errorInfo[2] : $e->getMessage();
         $model->addError('_exception', $msg);
     }
     return $this->render('create', ['model' => $model]);
 }
開發者ID:aixiaobenaixiaoben,項目名稱:find,代碼行數:19,代碼來源:UserController.php

示例3: actionBindAccount

 /**
  * 綁定賬號
  */
 public function actionBindAccount()
 {
     $this->layout = false;
     $old_login_uid = ZCommonSessionFun::get_user_id();
     if (ZCommonSessionFun::get_user_id() < 1) {
         $url = Yii::$app->urlManager->createUrl([ZCommonSessionFun::urlLoginUserStr]);
         return $this->redirect($url);
     }
     $model = new User();
     if (isset($_POST['User']['user']) && isset($_POST['op'])) {
         $post = $_POST['User'];
         $user = isset($post['user']) ? $post['user'] : '';
         $pass = isset($post['pass']) ? $post['pass'] : '';
         $post = $_POST['User'];
         //已有賬戶綁定
         if ($_POST['op'] == 1) {
             $condition['user'] = $user;
             $model_find = new User();
             $model_find = $model_find->find()->where($condition)->one();
             if (!$model_find) {
                 $model->addError('user', '用戶沒有找到');
             } else {
                 if ($model_find->pass != ZCommonFun::getPass($pass)) {
                     $model->addError('pass', '密碼錯誤');
                 } else {
                     if ($model_find->is_bind_user == 1) {
                         $model->addError('user', '賬戶已被綁定過');
                     } else {
                         $connection = Yii::$app->db;
                         $transaction = $connection->beginTransaction();
                         try {
                             $model_find->is_bind_user = 1;
                             $model_find->save();
                             $model_Oauth = new OauthBind();
                             $model_Oauth_condition['uid'] = $old_login_uid;
                             $model_Oauth_attributes['uid'] = $model_find->uid;
                             $model_Oauth->updateAll($model_Oauth_attributes, $model_Oauth_condition);
                             $transaction->commit();
                             ZCommonSessionFun::set_user_session($model_find->attributes);
                             $url = Yii::$app->urlManager->createUrl(['user-profile/bind-list']);
                             return $this->redirect($url);
                         } catch (\Exception $e) {
                             $transaction->rollBack();
                             $model->addError('user', '綁定失敗');
                         }
                     }
                 }
             }
         } else {
             $model->pass = ZCommonFun::getPass($model->pass);
             $model = $model->findOne(ZCommonSessionFun::get_user_id());
             if ($model) {
                 $model->user = $user;
                 $model->pass = ZCommonFun::getPass($pass);
                 $model->is_bind_user = 1;
                 if ($model->save()) {
                     ZCommonSessionFun::set_user_session($model->attributes);
                     $url = Yii::$app->urlManager->createUrl(['user-profile/bind-list']);
                     return $this->redirect($url);
                 }
             } else {
                 $model = new User();
                 $model->user = $user;
                 $model->pass = $pass;
                 $model->addError('user', '用戶已被刪除');
             }
         }
     }
     return $this->render('bind-account', ['model' => $model]);
 }
開發者ID:smilehaha,項目名稱:bag-test,代碼行數:73,代碼來源:UserProfileController.php


注:本文中的common\models\User::addError方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。