当前位置: 首页>>代码示例>>PHP>>正文


PHP User::load方法代码示例

本文整理汇总了PHP中app\modules\user\models\User::load方法的典型用法代码示例。如果您正苦于以下问题:PHP User::load方法的具体用法?PHP User::load怎么用?PHP User::load使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在app\modules\user\models\User的用法示例。


在下文中一共展示了User::load方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
开发者ID:obedkin,项目名称:atlant,代码行数:14,代码来源:DefaultController.php

示例2: actionCreate

 /**
  * Creates a new Person model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Person();
     $modelUser = new User();
     $modelAuthRule = new AuthRule();
     $modelAuthItem = new AuthItem();
     $authRule = AuthRule::find()->all();
     $authItem = AuthItem::find()->all();
     if (Yii::$app->request->isPost) {
         // do transaction if fails it will not saved
         $transaction = Yii::$app->db->beginTransaction();
         try {
             if ($modelUser->load(Yii::$app->request->post()) && $modelUser->validate()) {
                 $modelUser->generateAuthKey();
                 // first attempt save user record
                 if ($modelUser->save()) {
                     if ($model->load(Yii::$app->request->post())) {
                         $model->user_id = $modelUser->id;
                         // second attemp save person record
                         if ($model->validate() && $model->save()) {
                             if ($modelAuthItem->load(Yii::$app->request->post()) && $modelAuthItem->validate()) {
                                 $auth = Yii::$app->authManager;
                                 $role = $auth->getRole($modelAuthItem->name);
                                 if (!empty($role)) {
                                     // thrid attemp assign role to user
                                     $auth->assign($role, $modelUser->id);
                                     $transaction->commit();
                                     Yii::$app->getSession()->setFlash('success', Yii::t('app', 'Data Karyawan Berhasil Disimpan'));
                                     return $this->redirect(['index']);
                                 } else {
                                     throw new \Exception("AuthRole search data checkpoint fail to save");
                                 }
                             } else {
                                 throw new \Exception("AuthItem (Role) validation checkpoint fail to save");
                             }
                         } else {
                             throw new \Exception("Person save checkpoint fail to save");
                         }
                     } else {
                         throw new \Exception("Person loaded checkpoint fail to save");
                     }
                 } else {
                     throw new \Exception("User save checkpoint fail to save");
                 }
             } else {
                 throw new \Exception("User validation checkpoint fail to save");
             }
         } catch (\Exception $e) {
             $transaction->rollback();
             Yii::$app->getSession()->setFlash('error', Yii::t('app', 'Data Karyawan Gagal Disimpan'));
         }
     }
     return $this->render('create', ['model' => $model, 'modelUser' => $modelUser, 'modelAuthRule' => $modelAuthRule, 'authRule' => $authRule, 'modelAuthItem' => $modelAuthItem, 'authItem' => $authItem]);
 }
开发者ID:nicovicz,项目名称:portalctv,代码行数:59,代码来源:PersonController.php

示例3: actionCreate

 public function actionCreate()
 {
     $model = new User(['scenario' => 'admin-create']);
     $statusArray = User::getStatusArray();
     $roleArray = User::getRoleArray();
     if ($model->load(Yii::$app->request->post())) {
         if ($model->save()) {
             return $this->redirect(['index']);
         }
     }
     return $this->render('create', ['model' => $model, 'statusArray' => $statusArray, 'roleArray' => $roleArray]);
 }
开发者ID:psych88,项目名称:fifa,代码行数:12,代码来源:BackendController.php

示例4: Register

 public function Register()
 {
     if ($this->validate()) {
         $user = new User();
         $userProps['User'] = $this->getAttributes();
         $user->load($userProps);
         $user->save();
         Yii::$app->user->login($user, 60 * 60 * 24 * 365);
         return true;
     } else {
         return false;
     }
 }
开发者ID:borzenkovdev,项目名称:startkit_yii2,代码行数:13,代码来源:RegForm.php

示例5: 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();
     if ($model->load(Yii::$app->request->post())) {
         $security = new Security();
         $model->password = $security->generatePasswordHash(md5($model->password));
         $model->auth_key = $security->generateRandomString(64);
         $model->created_date = time();
         if ($model->save()) {
             return $this->redirect(['view', 'id' => $model->id]);
         }
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
开发者ID:pham186,项目名称:yii2,代码行数:20,代码来源:UserController.php

示例6: actionCreate

 public function actionCreate()
 {
     $user = new User(['scenario' => 'admin-create']);
     $profile = new Profile();
     $statusArray = User::getStatusArray();
     $roleArray = User::getRoleArray();
     if ($user->load(Yii::$app->request->post())) {
         if ($user->validate()) {
             $transaction = Yii::$app->db->beginTransaction();
             if ($user->save(false)) {
                 $profile->user_id = $user->getId();
                 if ($profile->save(false)) {
                     $transaction->commit();
                     return $this->redirect(['index']);
                 } else {
                     $transaction->rollback();
                     print_r($user->getErrors());
                     return false;
                 }
             } else {
                 Yii::$app->session->setFlash('danger', 'Ошибка');
                 return $this->refresh();
             }
         }
     }
     // $transaction = Yii::$app->db->beginTransaction();
     //     if ($user->save())
     //     {
     //         $profile->user_id = $user->getId();
     //         if($profile->save())
     //         {
     //             $transaction->commit();
     //             return $user;
     //         }
     //     }
     //     else
     //     {
     //         $transaction->rollback();
     //         print_r($user->getErrors());
     //         return false;
     //     }
     return $this->render('create', ['model' => $user, 'statusArray' => $statusArray, 'roleArray' => $roleArray]);
 }
开发者ID:akula22,项目名称:fifa,代码行数:43,代码来源:BackendController.php


注:本文中的app\modules\user\models\User::load方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。