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


PHP User::save方法代碼示例

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


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

示例1: addUser

    public function addUser($ldap)
    {
        $profile = Yii::$app->userHelpers->getUserProfileFromHr($ldap->citizen);
        $profile['moo'] = empty($profile['moo']) ? '' : ' หมู่ ' . $profile['moo'];
        $profile['soi'] = empty($profile['soi']) ? '' : ' ซอย ' . $profile['soi'];
        $profile['street'] = empty($profile['street']) ? '' : ' ถ.' . $profile['street'];
        $profile['district'] = empty($profile['district']) ? '' : ' ต.' . $profile['district'];
        $profile['amphur'] = empty($profile['amphur']) ? '' : ' อ.' . $profile['amphur'];
        $profile['province'] = empty($profile['province']) ? '' : ' จ.' . $profile['province'];
        $profile['zipcode'] = empty($profile['zipcode']) ? '' : ' ' . $profile['zipcode'];
        $user = new User();
        $user->id = $profile['id'];
        $user->username = $this->username;
        $user->email = "{$this->username}@kku.ac.th";
        $user->password_hash = Password::hash($this->password);
        $user->save(false);
        $connection = new Connection(Yii::$app->db);
        $connection->createCommand('INSERT INTO auth_assignment VALUES(:item_name, :user_id, :created_at)', [':item_name' => 'User', ':user_id' => $profile['id'], ':created_at' => time()])->execute();
        $admins = Yii::$app->getModule('user')->admins;
        if (in_array($ldap->username, $admins)) {
            $connection->createCommand('INSERT INTO auth_assignment VALUES(:item_name, :user_id, :created_at)', [':item_name' => 'Administrator', ':user_id' => $profile['id'], ':created_at' => time()])->execute();
        }
        $connection->createCommand('UPDATE profile SET
			name = :name,
			address = :address,
			phone = :phone,
			faculty_id = :faculty_id,
			position_id = :position_id,
			position_type_id = :position_type_id,
			level_id = :level_id,
			division_id = :division_id
			WHERE user_id = :user_id
		', [':name' => "{$profile['title']}{$profile['firstname']} {$profile['lastname']}", ':address' => "{$profile['homeadd']}{$profile['moo']}{$profile['soi']}{$profile['street']}{$profile['district']}{$profile['amphur']}{$profile['province']}{$profile['zipcode']}", ':phone' => isset($profile['telephone']) ? $profile['telephone'] : null, ':faculty_id' => isset($profile['faculty_id']) ? $profile['faculty_id'] : Yii::$app->mappingHelpers->mapFaculty($profile['faculty'])['id'], ':position_id' => isset($profile['position_id']) ? $profile['position_id'] : Yii::$app->mappingHelpers->mapPosition($profile['posi'])['id'], ':position_type_id' => isset($profile['position_type_id']) ? $profile['position_type_id'] : Yii::$app->mappingHelpers->mapPositionType($profile['positype'])['id'], ':level_id' => isset($profile['level_id']) ? $profile['level_id'] : Yii::$app->mappingHelpers->mapLevel($profile['level'])['id'], ':division_id' => isset($profile['division_id']) ? $profile['division_id'] : Yii::$app->mappingHelpers->mapDivision($profile['division'])['id'], ':user_id' => $profile['id']])->execute();
    }
開發者ID:pipekung,項目名稱:classes,代碼行數:34,代碼來源:Auth.php

示例2: login

 /**
  * Validates form and logs the user in.
  *
  * @return bool whether the user is logged in successfully
  */
 public function login()
 {
     if ($this->validate()) {
         if (Yii::$app->getUser()->login($this->user, $this->rememberMe ? $this->module->rememberFor : 0)) {
             UserLog::log("login-success");
             $this->user->last_login = gmdate("Y-m-d H:i:s");
             $this->user->save();
             return true;
         } else {
             return false;
         }
     } else {
         $message = '';
         foreach ($this->errors['login'] as $error) {
             $message .= $error . "\n";
         }
         UserLog::log("login-failure", $message);
         return false;
     }
 }
開發者ID:lnch,項目名稱:yii2-user-control,代碼行數:25,代碼來源:LoginForm.php


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