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


PHP User::load方法代碼示例

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


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

示例1: actionCreate

 /**
  * Creates a new User model.
  * For ajax request will return json object
  * and for non-ajax request if creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $request = Yii::$app->request;
     $model = new User();
     if ($request->isAjax) {
         /*
          *   Process for ajax request
          */
         Yii::$app->response->format = Response::FORMAT_JSON;
         if ($request->isGet) {
             return ['code' => '200', 'message' => 'OK', 'data' => $this->renderPartial('create', ['model' => $model])];
         } else {
             if ($model->load($request->post()) && $model->save()) {
                 return ['code' => '200', 'message' => 'Create User success'];
             } else {
                 return ['code' => '400', 'message' => 'Validate error', 'data' => $this->renderPartial('create', ['model' => $model])];
             }
         }
     } else {
         /*
          *   Process for non-ajax request
          */
         if ($model->load($request->post()) && $model->save()) {
             return $this->redirect(['view', 'id' => $model->id]);
         } else {
             return $this->render('create', ['model' => $model]);
         }
     }
 }
開發者ID:hdushku,項目名稱:npai,代碼行數:35,代碼來源: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: 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 = 'create';
     $userData = new UserData();
     //$hotelMapping = new UserHotelMapping();
     if ($model->load(Yii::$app->request->post()) && $userData->load(Yii::$app->request->post())) {
         $validUser = $model->validate();
         $validUserData = $userData->validate();
         //$validHotelMapping = $hotelMapping->validate();
         if ($validUser && $validUserData) {
             // && $validHotelMapping
             $model->setPassword($model->password);
             $model->generateAuthKey();
             if ($model->save()) {
                 $userData->user_id = $model->id;
                 //$hotelMapping->user_id = $model->id;
                 $userData->save(false);
                 //$hotelMapping->save(false);
                 return $this->redirect(['view', 'id' => $model->id]);
             }
         }
     }
     return $this->render('create', ['model' => $model, 'userData' => $userData]);
 }
開發者ID:vetal2409,項目名稱:example,代碼行數:30,代碼來源:UserController.php

示例4: actionCreate

 public function actionCreate()
 {
     $model = new User();
     if ($model->load(Yii::$app->request->post())) {
         if ($model->save()) {
             $str = 'abcefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890' . date('yyydmmdhis');
             $potong = str_shuffle($str);
             $random = substr($potong, 3, 12);
             $model->setPassword($random);
             $model->username = $_POST['User']['username'];
             $model->role = $_POST['User']['role'];
             $model->generateAuthKey();
             $content = '
                 <center><img src="http://i.imgur.com/p5lHZXS.png"/></center><br/>
                 <h4 align="center">Badan Pengawas Tenaga Nuklir  ' . date('Y') . '</h4>
                 <hr/>
                 <p>Yth ' . $model->username . ',<br/>  
                 Dengan ini kami sampaikan akun telah terdaftar untuk masuk ke Sistem Aplikasi Perjalanan Dinas – BAPETEN, sebagai berikut:<br/> 
                 Username : ' . $model->username . ' <br/>
                 Password :<b>' . $random . '</b><br/>
                 Mohon lakukan penggantian password Anda setelah melakukan login.\\n
                 Terima Kasih. <hr/>
                 <h5 align="center">Subbag Perjalanan Dinas Biro Umum BAPETEN  ' . date('Y') . '</h5><br/>';
             Yii::$app->mailer->compose("@common/mail/layouts/html", ["content" => $content])->setTo($_POST['User']['email'])->setFrom([$_POST['User']['email'] => $model->username])->setSubject('Ubah Kata Sandi')->setTextBody($random)->send();
             $model->save();
             return $this->redirect(['index']);
         } else {
             var_dump($model->errors);
         }
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
開發者ID:ilhammalik,項目名稱:yii2-advanced-beta,代碼行數:33,代碼來源:UserController.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($id)
 {
     $model = new User();
     $model->loadDefaultValues();
     $model->contact_id = $id;
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         //return $this->redirect(['contact/view', 'id' => $model->contact_id]);
         return $this->redirect(Url::previous());
     } elseif (!Yii::$app->request->isPost) {
         $model->load(Yii::$app->request->get());
     }
     if (Yii::$app->request->isAjax) {
         return $this->renderAjax('_form', ['model' => $model]);
     }
     return $this->render('create', ['model' => $model]);
 }
開發者ID:jslight,項目名稱:helpdesk,代碼行數:21,代碼來源:UserController.php

示例6: actionCreateuser

 public function actionCreateuser()
 {
     $userModel = User::findOne(['user_name' => yii::$app->request->post('user_name')]);
     if ($userModel === null) {
         $userModel = new User();
         $userModel->load(yii::$app->request->post());
         if ($userModel->save()) {
             yii::$app->AjaxResponse->error = false;
             yii::$app->AjaxResponse->message = ['User has been created'];
             yii::$app->UserComponent->sendWelcomeEmail($userModel->first_name, $userModel->email);
         } else {
             yii::$app->AjaxResponse->message = array_values($userModel->getErrors());
         }
     } else {
         // user exits but is not active
         if ($userModel->status_id != Types::$status['active']['id']) {
             $userModel->status_id = Types::$status['active']['id'];
             $userModel->save();
             yii::$app->AjaxResponse->error = false;
             yii::$app->AjaxResponse->message = ['User reactivated'];
         } else {
             yii::$app->AjaxResponse->message = ['User already exists'];
         }
     }
     yii::$app->AjaxResponse->sendContent();
 }
開發者ID:spiro-stathakis,項目名稱:projects,代碼行數:26,代碼來源:AjaxController.php

示例7: 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->created_by = Yii::$app->user->identity->username;
         $model->created_date = date('Y-m-d h:m:s');
         $model->modified_by = Yii::$app->user->identity->username;
         $model->modified_date = date('Y-m-d h:m:s');
         $model->status = Status::STATUS_ACTIVE;
         $model->generateUserActivationCode();
         //            $model->password_hash = md5($model->auth_key);
         //            $model->save();
         $imageName = substr(md5(rand()), 0, 7);
         if (UploadedFile::getInstance($model, 'file')) {
             $model->file = UploadedFile::getInstance($model, 'file');
             $model->image_path = 'uploads/user/' . $model->file->baseName . $imageName . '.' . $model->file->extension;
         }
         if ($model->save()) {
             if ($model->image_path != null) {
                 $model->file->saveAs('uploads/user/' . $model->file->baseName . $imageName . '.' . $model->file->extension);
                 return $this->redirect(['view', 'id' => $model->id]);
             }
         } else {
             Yii::$app->session->setFlash('error', 'Insert Failed.');
             return $this->render('create', ['model' => $model]);
         }
         Yii::$app->session->setFlash('success', 'Insert Success.');
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
開發者ID:noorafree,項目名稱:makmakan,代碼行數:37,代碼來源:UserController.php

示例8: 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->username = $_POST['User']['username'];
         $model->email = $_POST['User']['email'];
         $model->password = $_POST['User']['password'];
         $model->setPassword($_POST['User']['password']);
         $model->generateAuthKey();
         $model->fname = $_POST['User']['fname'];
         $model->lname = $_POST['User']['lname'];
         $model->groupid = $_POST['User']['groupid'];
         $model->departmentid = $_POST['User']['departmentid'];
         //  $model->roleid = $_POST['User']['roleid'];
         $model->roleid = 2;
         if ($model->save()) {
             return $this->redirect(['view', 'id' => $model->id]);
         } else {
             print_r($model->getErrors());
         }
         //            if ($id = $model->signup() ) {
         //                return $this->redirect(['view', 'id' => $id->id]);
         //            }
         //            if(is_null($model->signup())){
         //              //  echo "Value is null";
         //                print_r($model->getErrors());
         //            }
     }
     return $this->render('create', ['model' => $model]);
 }
開發者ID:nirantarnoy,項目名稱:paperless,代碼行數:35,代碼來源:UserController.php

示例9: 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

示例10: actionReset

 public function actionReset()
 {
     $this->layout = 'login';
     $model = new User();
     if ($model->load(Yii::$app->request->post())) {
         if ($_POST['User']) {
             $model->attributes = $_POST['User'];
             $valid = $model->validate();
             if ($valid) {
                 $model = User::find()->where(['email' => $_POST['User']['email']])->one();
                 $str = date('ymdhis') . 'abcefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890' . date('d');
                 $potong = str_shuffle($str);
                 $random = substr($potong, 3, 12);
                 $model->setPassword($random);
                 $content = '
                 <center><img src="http://i.imgur.com/p5lHZXS.png"/></center><br/>
                 <h4 align="center">Badan Pengawas Tenaga Nuklir  ' . date('Y') . '</h4>
                 <hr/>
                 <p>Yth ' . $model->username . ',<br/>  
                 Dengan ini kami sampaikan password telah direset  sebagai berikut:<br/> 
                 Username : ' . $model->username . ' <br/>
                 Password :<b>' . $random . '</b><br/>
                 Mohon lakukan penggantian password Anda setelah melakukan login. <hr/>
                 <h5 align="center">Subbag Perjalanan Dinas Biro Umum BAPETEN  ' . date('Y') . '</h5><br/>';
                 Yii::$app->mailer->compose("@common/mail/layouts/html", ["content" => $content])->setTo($_POST['User']['email'])->setFrom([$_POST['User']['email'] => 'Aplikasi Simpel Bapeten'])->setSubject('Ubah Kata Sandi')->setTextBody($random)->send();
                 $model->save();
                 return $this->redirect(['/site/login']);
             }
         }
     }
     return $this->render('reset', ['model' => $model]);
 }
開發者ID:ilhammalik,項目名稱:yii2-advanced-beta,代碼行數:32,代碼來源:SiteController.php

示例11: actionCreate

 public function actionCreate()
 {
     $model = new User();
     $model->scenario = 'create';
     $users['User'] = Yii::$app->request->post();
     if (Yii::$app->request->isPost && $model->load($users)) {
         $model->password_hash = Yii::$app->request->post('password');
         if (!empty($_FILES)) {
             $upload = new UploadedFile();
             $upload->name = $_FILES['image']['name'];
             $upload->type = $_FILES['image']['type'];
             $upload->tempName = $_FILES['image']['tmp_name'];
             $upload->error = $_FILES['image']['error'];
             $upload->size = $_FILES['image']['size'];
             $model->image = $upload;
             $filepath = Yii::getAlias('@uploadpath');
             $model->image->saveAs($filepath . '/' . $model->image->baseName . '.' . $model->image->extension);
             $model->setImage($model->image->name, FALSE);
         }
         if ($model->save()) {
             return $model;
         } else {
             return $model->getErrors();
         }
     } else {
         throw new ForbiddenHttpException('User is not saved successfully. Please try again with proper details.');
     }
 }
開發者ID:sunil120,項目名稱:yii2,代碼行數:28,代碼來源:UserController.php

示例12: 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:lukianovva,項目名稱:clover,代碼行數:14,代碼來源:DefaultController.php

示例13: 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()) {
         Yii::$app->session->setFlash('success', 'Well done! successfully to save data!  ');
         return $this->redirect(['index']);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
開發者ID:sintret,項目名稱:yii2-advanced,代碼行數:15,代碼來源:UserController.php

示例14: actionCreate

 /**
  * Creates a new User model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     /* @TODO: Remove this function later */
     throw new \yii\web\ForbiddenHttpException('This method has been removed!');
     $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:wadeshuler,項目名稱:yii2-members-system,代碼行數:16,代碼來源:UserController.php

示例15: 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 = 'create';
     if (Yii::$app->request->isPost) {
         if ($model->load(Yii::$app->request->post()) && $model->save()) {
             return $this->redirect(['index']);
         }
     }
     return $this->render('create', ['model' => $model]);
 }
開發者ID:Penton,項目名稱:MoBlog,代碼行數:16,代碼來源:UserController.php


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