当前位置: 首页>>代码示例>>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;未经允许,请勿转载。