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


PHP User::setAttributes方法代码示例

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


在下文中一共展示了User::setAttributes方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: register

 /**
  * Registers a new user account.
  * @return bool
  */
 public function register()
 {
     if (!$this->validate()) {
         return false;
     }
     $this->user->setAttributes(['email' => $this->email, 'username' => $this->username, 'password' => $this->password, 'firstName' => $this->firstName, 'lastName' => $this->lastName]);
     return $this->user->register();
 }
开发者ID:AnduZhang,项目名称:nws,代码行数:12,代码来源:RegistrationForm.php

示例2: actionRegister

 public function actionRegister()
 {
     $errors = null;
     $model = new UserForm();
     if (Yii::$app->request->isPost) {
         $model->setAttributes(Yii::$app->request->post());
         if ($model->validate()) {
             $user = new User();
             $user->setAttributes($model->getAttributes());
             $user->setPassword($model->password);
             $user->generateAuthKey();
             $save = $user->save();
             if ($save) {
                 $purse = new Purse();
                 $purse->user_id = $user->id;
                 $purse->active = 1;
                 $purse->balance = 0;
                 $purse->name = "Основной";
                 $purse->save();
                 $login = Yii::$app->user->login($user, 3600 * 24 * 14);
                 if ($login) {
                     return $this->goHome();
                 }
             }
         } else {
             $errors = $model->getErrors();
         }
     }
     return $this->renderPartial('register', ['errors' => $errors, 'model' => $model]);
 }
开发者ID:RStuffGit,项目名称:money,代码行数:30,代码来源:MainController.php

示例3: create

 /**
  * @param $data array
  * @param $password string
  * @return User
  */
 public function create($data, $password)
 {
     $user = new User();
     $user->setAttributes($data);
     $user->group = User::GROUP_USER;
     $user->setPassword($password);
     $user->authKey = Yii::$app->security->generateRandomString();
     $this->saveOrFail($user);
     return $user;
 }
开发者ID:sly13,项目名称:maps,代码行数:15,代码来源:UserRepository.php

示例4: actionCreate

 public function actionCreate()
 {
     $model = new User();
     $model->setAction('admin-insert');
     if (isset($_POST['save'])) {
         $model->setAttributes($_POST['User']);
         if ($model->validate() && $model->adminCreate()) {
             Messages::get()->success("User created!");
             $this->getRequest()->goToPage('users', 'index');
         }
     }
     $this->assign('model', $model);
 }
开发者ID:mpf-soft,项目名称:app-basic,代码行数:13,代码来源:Users.php

示例5: register

 /**
  * @return bool
  */
 public function register()
 {
     if ($this->validate()) {
         $user = new User();
         if (User::SCENARIO_PERSON == $this->status) {
             $user->setScenario($this->status);
         } elseif (User::SCENARIO_COMPANY == $this->status) {
             $user->setScenario($this->status);
         } else {
             return false;
         }
         $user->setAttributes($this->getAttributes());
         $user->setPassword($this->password);
         return $user->save();
     }
     return false;
 }
开发者ID:Shumer596,项目名称:site.loc,代码行数:20,代码来源:RegistrationForm.php

示例6: actionCreateUser

 public function actionCreateUser()
 {
     $this->stdout("Create a new user...\n", Console::BOLD);
     $username = $this->prompt("Username: ", ['validator' => function ($input, &$error) {
         if (preg_match('/^[\\w\\d_\\.]+$/', $input)) {
             return true;
         }
         $error = "Username can only contain alphabet characters, numbers, dots and underscores.";
         return false;
     }]);
     $name = trim($this->prompt("Display name: ", ['validator' => function ($input, &$error) {
         $input = trim($input);
         if (preg_match('/^[\\w\\d_\\. ]+$/', $input)) {
             return true;
         }
         $error = "Display name must contain at least 1 visible character, and can only contain alphabet characters, numbers, dots, underscores and spaces. Leading and trailing spaces will be trimmed.";
         return false;
     }]));
     $password = $this->prompt("Password: ", ['validator' => function ($input, &$error) {
         if (preg_match('/^.{8,}$/', $input)) {
             return true;
         }
         $error = "Password must have at least 8 characters";
         return false;
     }]);
     $email = $this->prompt("Email: ", ['validator' => function ($input, &$error) {
         if (filter_var($input, FILTER_VALIDATE_EMAIL)) {
             return true;
         }
         $error = "Invalid email format";
         return false;
     }]);
     $role = $this->prompt("Role (administrator/moderator): ", ['validator' => function ($input, &$error) {
         if (preg_match('/^(administrator|moderator)$/', $input)) {
             return true;
         }
         $error = "Role must be either 'administrator' or 'moderator'";
         return false;
     }]);
     if ($this->confirm("Do you want to proceed with creating this user?")) {
         $model = new User();
         $model->scenario = User::SCENARIO_CONSOLE_CREATE;
         $model->setAttributes(['username' => $username, 'name' => $name, 'email' => $email, 'status' => User::STATUS_ACTIVE]);
         $model->setPassword($password);
         $model->generateAuthKey();
         $model->generateAccessToken();
         if ($model->save()) {
             $auth = Yii::$app->authManager;
             $role = $auth->getRole($role);
             $auth->assign($role, $model->id);
             $this->stdout("User '{$username}' has been created\n", Console::BOLD);
         } else {
             foreach ($model->errors as $key => $errors) {
                 foreach ($errors as $error) {
                     $this->stdout("'{$key}': {$error}", Console::BOLD);
                 }
             }
         }
     } else {
         $this->stdout("Aborting...\n", Console::BOLD);
     }
     return 0;
 }
开发者ID:btquanto,项目名称:yii-skeleton,代码行数:63,代码来源:RbacController.php


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