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


PHP User::insert方法代碼示例

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


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

示例1: actionRegister

 public function actionRegister()
 {
     if (!Application::$app->getUser()->getIsGuest()) {
         Application::$app->getSession()->setFlash('register-warning', 'You must be unauthorized');
         return $this->redirect('site/index');
     }
     if (!empty($_POST) && (!isset($_POST['email']) || empty($_POST['email']) || !isset($_POST['password']) || empty($_POST['password']) || !isset($_POST['repeat_password']) || empty($_POST['repeat_password']))) {
         Application::$app->getSession()->setFlash('register-danger', 'Please fill all fields.');
     } elseif (!empty($_POST) && $_POST['password'] !== $_POST['repeat_password']) {
         Application::$app->getSession()->setFlash('register-danger', 'Passwords not match.');
     } elseif (!empty($_POST)) {
         //check email
         $model = User::findIdentityByEmail($_POST['email']);
         if (!empty($model)) {
             Application::$app->getSession()->setFlash('register-danger', 'User with email ' . HtmlPurifier::process($_POST['email']) . ' already registered.');
             return $this->redirect('user/register');
         }
         $model = new User();
         $model->load($_POST);
         $model->insert();
         Application::$app->getSession()->setFlash('register-success', 'User successfully created.');
         return $this->redirect('user/login');
     }
     return $this->render('user/register');
 }
開發者ID:ercling,項目名稱:auth,代碼行數:25,代碼來源:UserController.php

示例2: InsertTestCode

 public function InsertTestCode()
 {
     $user = new User();
     $user->testcode = $this->GetTestCode(4);
     $user->telephone = $this->telephone;
     $isExist = User::find()->where(['telephone' => $user->telephone])->one();
     if (!empty($isExist)) {
         if (empty($isExist->username)) {
             if (User::updateAll(['testcode' => $user->testcode], 'telephone =' . $user->telephone)) {
                 $password = md5("ontee123ontee");
                 $content = urlencode("歡迎您注冊ONTEE,您的驗證碼" . $user->testcode . ",請在10分鍾之內輸入。【ONTEE】");
                 $time = $this->getMillisecond();
                 $remote_server = "http://api.sms.cn/mt/?uid=ontee&pwd=" . $password . "&mobile=" . $user->telephone . "&mobileids=" . $user->telephone . $time . "&content=" . $content . "&encode=utf8";
                 $data = $this->request_by_curl($remote_server);
                 echo $user->testcode;
             }
         } else {
             echo 0;
         }
     } else {
         if ($user->insert('user', ['testcode', 'telephone'], [$user->testcode, $user->telephone])) {
             $password = md5("ontee123ontee");
             $content = urlencode("歡迎您注冊ONTEE,您的驗證碼" . $user->testcode . ",請在10分鍾之內輸入。【ONTEE】");
             $time = $this->getMillisecond();
             $remote_server = "http://api.sms.cn/mt/?uid=ontee&pwd=" . $password . "&mobile=" . $user->telephone . "&mobileids=" . $user->telephone . $time . "&content=" . $content . "&encode=utf8";
             $data = $this->request_by_curl($remote_server);
             echo $user->testcode;
         }
     }
 }
開發者ID:xiaojianxin,項目名稱:Ontee,代碼行數:30,代碼來源:RegisterForm.php

示例3: register

 public function register($attributes)
 {
     $fields = ['fb_id' => $attributes['id'], 'datetime_reg' => gmdate('YmdHis'), 'datetime_activate' => gmdate('YmdHis'), 'is_active' => 1];
     if (ArrayHelper::getValue($attributes, 'first_name', '') != '') {
         $fields['name_first'] = ArrayHelper::getValue($attributes, 'first_name', '');
         $fields['name_last'] = ArrayHelper::getValue($attributes, 'last_name', '');
     } else {
         $fields['name_first'] = $attributes['name'];
     }
     if (ArrayHelper::getValue($attributes, 'fb_link', '') != '') {
         $fields['fb_link'] = $attributes['link'];
     }
     if (ArrayHelper::getValue($attributes, 'fb_link', '') != '') {
         $fields['gender'] = $attributes['gender'] == 'male' ? 1 : 0;
     }
     // добавляю поля для подписки
     foreach (\app\services\Subscribe::$userFieldList as $field) {
         $fields[$field] = 1;
     }
     if (isset($attributes['email'])) {
         $fields['email'] = $attributes['email'];
         $fields['is_confirm'] = 1;
     }
     $user = User::insert($fields);
     $user->setAvatarFromUrl('https://graph.facebook.com/' . $attributes['id'] . '/picture?type=large', 'jpg');
     return $user;
 }
開發者ID:Makeyko,項目名稱:galaxysss,代碼行數:27,代碼來源:Facebook.php

示例4: actionMail

 /**
  * AJAX
  * Создает подписку для авторизованного или неавторизованного пользователя
  * Высылает письмо подтверждения email
  *
  * @return string json
  *                error
  *                101, 'Такая почта уже зарегистрирована'
  */
 public function actionMail()
 {
     $email = self::getParam('email');
     $name = self::getParam('name');
     $email = strtolower($email);
     if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
         return self::jsonErrorId(101, 'Не корректная почта');
     }
     if (User::query(['email' => $email])->exists()) {
         return self::jsonErrorId(101, 'Такая почта уже зарегистрирована');
     }
     if (Yii::$app->user->isGuest) {
         $fields = ['email' => $email, 'datetime_reg' => gmdate('YmdHis'), 'is_active' => 0, 'is_confirm' => 0, 'name_first' => $name];
         foreach (Subscribe::$userFieldList as $field) {
             $fields[$field] = 1;
         }
         $user = User::insert($fields);
     } else {
         /** @var \app\models\User $user */
         $user = Yii::$app->user->identity;
         $fields = ['email' => $email, 'datetime_reg' => gmdate('YmdHis'), 'is_active' => 0, 'is_confirm' => 0];
         foreach (Subscribe::$userFieldList as $field) {
             $fields[$field] = 1;
         }
         $user->update($fields);
     }
     $fields = RegistrationDispatcher::add($user->getId());
     \cs\Application::mail($email, 'Подтверждение почты', 'subscribe_activate', ['url' => Url::to(['subscribe/activate', 'code' => $fields['code']], true), 'user' => $user, 'datetime' => \Yii::$app->formatter->asDatetime($fields['date_finish'])]);
     return self::jsonSuccess();
 }
開發者ID:Makeyko,項目名稱:galaxysss,代碼行數:39,代碼來源:SubscribeController.php

示例5: saveFBDetails

 public static function saveFBDetails($data)
 {
     if (!User::checkFBUser($data['fb_id'])) {
         User::insert($data);
         Notifier::sendSignupEmail($data['email'], $data['first_name'] . ' ' . $data['last_name']);
     }
 }
開發者ID:reminisense,項目名稱:featherq-laravel5,代碼行數:7,代碼來源:User.php

示例6: create

 function create()
 {
     $input = Request::all();
     $validator = Validator::make($input, array("name" => "required", "email" => "required|email|unique:users", "password" => "required|min:6", "password_again" => "same:password"));
     if ($validator->passes()) {
         User::insert($input);
         return redirect('user/login')->with('info', 'Register success!');
     } else {
         return redirect('user/register')->withErrors($validator);
     }
 }
開發者ID:eimg,項目名稱:laravel-example,代碼行數:11,代碼來源:UserController.php

示例7: register

 public function register($attributes)
 {
     $fields = ['vk_id' => $attributes['uid'], 'name_first' => $attributes['first_name'], 'name_last' => $attributes['last_name'], 'gender' => $attributes['sex'] == 0 ? null : ($attributes['sex'] == 1 ? 0 : 1), 'vk_link' => $attributes['screen_name'], 'datetime_reg' => gmdate('YmdHis'), 'datetime_activate' => gmdate('YmdHis'), 'is_active' => 1, 'is_confirm' => 0, 'birth_date' => $this->getBirthDate($attributes)];
     // добавляю поля для подписки
     foreach (\app\services\Subscribe::$userFieldList as $field) {
         $fields[$field] = 1;
     }
     $user = User::insert($fields);
     \Yii::info('$fields: ' . \yii\helpers\VarDumper::dumpAsString($fields), 'gs\\fb_registration');
     $user->setAvatarFromUrl($attributes['photo_200']);
     return $user;
 }
開發者ID:CAPITALOV,項目名稱:capitalov,代碼行數:12,代碼來源:VKontakte.php

示例8: saveUser

 public static function saveUser($data)
 {
     $user = new User();
     $user->username = $data['username'];
     $user->email = $data['email'];
     $user->password = md5($data['password']);
     $user->type_id = $data['type_id'];
     if ($user->insert()) {
         return true;
     } else {
         return false;
     }
 }
開發者ID:Salvadore1987,項目名稱:dev.medical.uz,代碼行數:13,代碼來源:User.php

示例9: create

 public function create(Request $request)
 {
     $validator = Validator::make($request->all(), ['email' => 'required|email|unique:users', 'phone' => 'required|unique:users', 'password' => 'required|same:repassword']);
     if ($validator->fails()) {
         return \Redirect::back()->withErrors($validator)->withInput();
     } else {
         $inputData = $request->only('email', 'password', 'fullname', 'phone', 'role', 'priority');
         $inputData['password'] = Hash::make($inputData['password']);
         if (User::insert($inputData)) {
             return \Redirect::back()->with('responseData', array('statusCode' => 1, 'message' => 'Thêm mới thành công'));
         } else {
             return \Redirect::back()->withInput()->with('responseData', array('statusCode' => 2, 'message' => 'Có lỗi xảy ra, vui lòng thử lại'));
         }
     }
 }
開發者ID:phamnhuson,項目名稱:VDNABARCODE,代碼行數:15,代碼來源:UserController.php

示例10: register

 public function register($attributes)
 {
     $fields = ['fb_id' => $attributes['id'], 'fb_link' => $attributes['link'], 'name_first' => $attributes['first_name'], 'name_last' => $attributes['last_name'], 'gender' => $attributes['gender'] == '' ? null : ($attributes['gender'] == 'male' ? 1 : 0), 'datetime_reg' => gmdate('YmdHis'), 'datetime_activate' => gmdate('YmdHis'), 'is_active' => 1, 'is_confirm' => 1];
     // добавляю поля для подписки
     foreach (\app\services\Subscribe::$userFieldList as $field) {
         $fields[$field] = 1;
     }
     if (isset($attributes['email'])) {
         $fields['email'] = $attributes['email'];
     }
     \Yii::info('$fields: ' . \yii\helpers\VarDumper::dumpAsString($fields), 'gs\\fb_registration');
     $user = User::insert($fields);
     $user->setAvatarFromUrl('https://graph.facebook.com/' . $attributes['id'] . '/picture?type=large');
     return $user;
 }
開發者ID:CAPITALOV,項目名稱:capitalov,代碼行數:15,代碼來源:Facebook.php

示例11: actionMail

 /**
  * AJAX
  * Создает подписку для авторизованного или неавторизованного пользователя
  * Высылает письмо подтверждения email
  *
  * @return string json
  *                error
  *                101, 'Такая почта уже зарегистрирована'
  */
 public function actionMail()
 {
     $email = self::getParam('email');
     $name = self::getParam('name');
     if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
         return self::jsonErrorId(101, 'Не корректный формат адреса');
     }
     $email = strtolower($email);
     $user = User::find(['email' => $email, 'subscribe_is_tesla' => 1]);
     if ($user) {
         $user->update(['subscribe_is_tesla' => 1]);
     } else {
         $fields = ['email' => $email, 'datetime_reg' => gmdate('YmdHis'), 'is_active' => 1, 'is_confirm' => 0, 'name_first' => $name, 'subscribe_is_tesla' => 1];
         $user = User::insert($fields);
         $fields = RegistrationDispatcher::add($user->getId());
         \cs\Application::mail($email, 'Подтверждение почты', 'subscribe_activate', ['url' => Url::to(['subscribe/activate', 'code' => $fields['code']], true), 'user' => $user, 'datetime' => \Yii::$app->formatter->asDatetime($fields['date_finish'])]);
     }
     return self::jsonSuccess();
 }
開發者ID:dram1008,項目名稱:gleb,代碼行數:28,代碼來源:SubscribeController.php

示例12: signupAction

 public function signupAction()
 {
     $form = new UserForm($this);
     if ($this->POST) {
         if ($form->validate($_POST)) {
             // Form output
             $data = $form->output;
             // Save user
             $uid = User::insert($data['default']);
             // Get user
             $account = User::get($uid);
             // Set password
             $account->setPassword($data['private']['password']);
             // Notify
             Session::success('Account created!');
             // Redirect
             return $this->_redirect('user/login');
         }
     }
     return get_defined_vars();
 }
開發者ID:rudiedirkx,項目名稱:SocialPay,代碼行數:21,代碼來源:userController.php

示例13: insert

 /**
  * Делает заказ
  *
  * @param  int $id идентификатор генератора
  *
  * @return boolean whether the model passes validation
  */
 public function insert($fieldsCols = null)
 {
     $id = $fieldsCols;
     $request = parent::insert(['beforeInsert' => function ($fields) {
         $fields['email'] = strtolower($fields['email']);
         $fields['datetime'] = time();
         $fields['status'] = \app\models\Request::STATUS_1_WAIT;
         return $fields;
     }]);
     if ($request === false) {
         return false;
     }
     $request['product_id'] = $id;
     $this->email = strtolower($this->email);
     if (!Yii::$app->user->isGuest) {
         $user = Yii::$app->user->identity;
         $request = new \app\models\Request($request);
         $request->update(['user_id' => Yii::$app->user->getId(), 'product_id' => $id]);
         // письмо клиенту
         $result = \cs\Application::mail($user->getEmail(), 'Вы сделали очередной заказ', 'next_request_client', ['user' => $user, 'request' => $request]);
     } else {
         $fields = ['email' => $this->email, 'datetime_reg' => gmdate('YmdHis'), 'is_active' => 1, 'is_confirm' => 0, 'subscribe_is_tesla' => 1, 'name_first' => $this->name, 'phone' => $this->phone];
         $user = User::insert($fields);
         $fields = \app\services\RegistrationDispatcher::add($user->getId());
         $request = new \app\models\Request($request);
         $request->update(['user_id' => $user->getId(), 'product_id' => $id]);
         // письмо им
         \cs\Application::mail($this->email, 'Поздравляем вы сделали первый шаг к своему полю коллективного счастья', 'new_request_client', ['url' => Url::to(['site/activate', 'code' => $fields['code']], true), 'user' => $user, 'request' => $request]);
     }
     foreach (\Yii::$app->params['requestMailList'] as $item) {
         // письмо нам
         $result = Application::mail($item, 'Появился заказ на TeslaGen', 'new_request', ['request' => $request, 'user' => $user]);
         //            VarDumper::dump([$result,$item]);
     }
     return $request;
 }
開發者ID:dram1008,項目名稱:bogdan,代碼行數:43,代碼來源:Request.php

示例14: postRegister

 /**
  * Registration process
  */
 public function postRegister()
 {
     //Form not valid
     $validator = true;
     //Error messages
     $data['register_error_messages'] = [];
     //Username
     if (!isset($_POST['username']) || $_POST['username'] == '') {
         //Set error message for registration form username
         $data['register_error_messages']['username'] = 'Username is required!';
         //Validator is false
         $validator = false;
     }
     if (!isset($_POST['password']) || $_POST['password'] == '') {
         //Set error message for registration form password
         $data['register_error_messages']['password'] = 'Password is required!';
         //Validator is false
         $validator = false;
     }
     if (!isset($_POST['email']) || $_POST['email'] == '') {
         //Set error message for registration form email
         $data['register_error_messages']['email'] = 'E-mail is required!';
         //Validator is false
         $validator = false;
     }
     //If form is valid the continue processing
     if ($validator) {
         //Create new user model
         $user = new User();
         //Create new hash
         $hash = new Hash();
         //Get user data
         $data = ['username' => $_POST['username'], 'password' => $hash->make($_POST['password']), 'email' => $_POST['email'], 'created_at' => date('Y-m-d H:i:s')];
         //Send data to database
         $results = $user->insert($data);
         if ($results) {
             //Set success message
             $data['alert_msg'] = 'Your account has been created';
             //Reload page
             view('login-register', $data);
         } else {
             //Set error message
             $data['alert_msg'] = 'Your Could not be created';
             //Reload page
             view('login-register', $data);
         }
     } else {
         //Form is not valid
         view('login-register', $data);
     }
 }
開發者ID:AshniSukhoo,項目名稱:blog,代碼行數:54,代碼來源:AuthController.php

示例15: User

<?php

/**
 * Тестирование ActiveRecord
 */
//use App\Db;
use App\Models\User;
require_once __DIR__ . '/../../index.php';
/**
 * Тестирование метода insert() в классе Model
 */
$user = new User();
$user->name = 'Андрей';
$user->email = 'a@vasnecov.ru';
echo 'Добавили: ' . $user->insert() . '<br>';
echo 'id новой записи: ' . $user->id;
echo '<hr>';
/**
 * Тестирование метода update() в классе Model
 */
$id = 2;
$user = App\Models\User::findById($id);
$user->name = 'Светлана';
$user->email = 's@sss.ru';
echo 'Изменена ли запись с id=' . $id . ': ' . $user->update();
echo '<hr>';
/**
 * Тестирование метода save() в классе Model => вызов insert()
 */
$user = new User();
$user->name = 'Агрипина';
開發者ID:webmaza75,項目名稱:php2,代碼行數:31,代碼來源:test_active_record.php


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