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


PHP User::findOne方法代碼示例

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


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

示例1: actionCreate

 /**
  * Creates a new Message model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @param $receiver : to some body send a msg
  * @return mixed
  * @throws BadRequestHttpException
  */
 public function actionCreate($receiver)
 {
     $this->layout = '//i';
     if ($receiver == Yii::$app->user->id) {
         throw new BadRequestHttpException('給自己發消息有意思不', 403);
     }
     $receiverUser = User::findOne($receiver);
     $model = new Message();
     $model->receiver = $receiver;
     $model->sender = Yii::$app->user->id;
     $model->user_id = $receiver;
     $model->friend_id = Yii::$app->user->id;
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         $msg = new Message();
         $msg->receiver = $receiver;
         $msg->sender = Yii::$app->user->id;
         $msg->user_id = $model->sender;
         $msg->friend_id = $model->receiver;
         $msg->content = $model->content;
         $msg->save(false);
         return $this->redirect(['index']);
     } else {
         var_dump($model->errors);
         return $this->render('create', ['model' => $model, 'receiverUser' => $receiverUser]);
     }
 }
開發者ID:awebc,項目名稱:web_xbf,代碼行數:33,代碼來源:MessageController.php

示例2: actionLogin

 public function actionLogin()
 {
     $result = false;
     $token = '';
     $accessToken = Yii::$app->request->get('access_token');
     if ($accessToken) {
         if (User::findOne(['access_token' => $accessToken])) {
             $result = true;
         }
     } elseif (Yii::$app->request->post('username') && Yii::$app->request->post('password')) {
         $user = User::findByUsername(Yii::$app->request->post('username'));
         if ($user && $user->validatePassword(Yii::$app->request->post('password'))) {
             if ($user->access_token) {
                 $token = $user->access_token;
             } else {
                 $token = hash('sha256', Yii::$app->request->get('username'));
                 Yii::$app->db->createCommand()->update("user", ['access_token' => $token], 'id = ' . $user->id)->execute();
             }
             $result = true;
         }
     }
     if ($result) {
         return ['result' => 'success', 'access_token' => $token];
     } else {
         return ['result' => 'failed'];
     }
 }
開發者ID:laojiu,項目名稱:yii2-advanced-funson86,代碼行數:27,代碼來源:UserController.php

示例3: create

 public function create()
 {
     $isValid = false;
     $this->imageFile = UploadedFile::getInstance($this, 'imageFile');
     $user = User::findOne(Yii::$app->user->getId());
     $bulletin = new Bulletin();
     if (isset($this->imageFile)) {
         $imagePath = '/uploads/' . $this->imageFile->baseName . '.' . $this->imageFile->extension;
         $this->imageFile->saveAs(Yii::getAlias('@webroot') . $imagePath);
         $m_image = new Image();
         $m_image->url = $imagePath;
         if ($m_image->save()) {
             $image = Image::findOne($m_image->getPrimaryKey());
             $bulletin->link('image', $image);
             $bulletin->link('user', $user);
             $isValid = true;
         } else {
             $isValid = false;
         }
     }
     $bulletin->title = $this->title;
     $bulletin->description = $this->description;
     if ($bulletin->save()) {
         $isValid = true;
     } else {
         $isValid = false;
     }
     return $isValid;
 }
開發者ID:arcanums,項目名稱:boardbull,代碼行數:29,代碼來源:BulletinForm.php

示例4: isAdminSelfEdit

 private function isAdminSelfEdit()
 {
     if (!Yii::$app->user->isGuest) {
         return $this->username === User::findOne(Yii::$app->user->id)->username;
     }
     return false;
 }
開發者ID:Ravend6,項目名稱:php_yii2_ecommerce,代碼行數:7,代碼來源:User.php

示例5: actionComment

 public function actionComment()
 {
     if (Yii::$app->request->isAjax) {
         Yii::$app->response->format = Response::FORMAT_JSON;
         $data = Yii::$app->request->post();
         $user = User::findOne(Yii::$app->user->getId());
         $whom = User::findOne($data['whom_id']);
         $rate = $whom->profile->rate;
         if ($rate == 0) {
             $whom->profile->rate = (double) $data['rate'];
         } else {
             $whom->profile->rate = ($rate + (double) $data['rate']) / 2;
         }
         $whom->profile->save();
         $comment = new Comment();
         $comment->rate = $data['rate'];
         $comment->description = $data['comment'];
         $comment->whom_id = $data['whom_id'];
         $comment->link('owner', $user);
         if ($comment->save()) {
             return array('success' => true);
         }
         return array('success' => false);
     }
 }
開發者ID:arcanums,項目名稱:boardbull,代碼行數:25,代碼來源:CommentController.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: getUser

 /**
  * Finds user by [[email]]
  *
  * @return User|null
  */
 public function getUser()
 {
     if ($this->_user === false) {
         $this->_user = User::findOne(['email' => $this->email]);
     }
     return $this->_user;
 }
開發者ID:darkffh,項目名稱:yii2-lowbase,代碼行數:12,代碼來源:LoginForm.php

示例8: finishReg

 public function finishReg($id)
 {
     /* @var $modelUser \common\models\User */
     /* @var $modelPlaceCountry \common\models\PlaceCountry */
     $modelUser = User::findOne($id);
     if ($this->scenario === 'phoneFinish') {
         $modelUser->phone = $this->getPhoneNumber();
         $modelUser->status = User::STATUS_ACTIVE;
         $modelUser->country_id = $this->country_id;
         $modelUser->setPassword(time());
         $modelUser->generateAuthKey();
         $modelUser->save();
         return RbacHelper::assignRole($modelUser->getId()) ? $modelUser : null;
     } elseif ($this->scenario === 'phoneAndEmailFinish') {
         $modelUser->phone = $this->getPhoneNumber();
         $modelUser->email = $this->email;
         $modelUser->country_id = $this->country_id;
         $modelUser->setPassword($this->password);
         $modelUser->generateAuthKey();
         $modelUser->generateSecretKey();
         $modelUser->validate();
         $modelUser->save();
         return RbacHelper::assignRole($modelUser->getId()) ? $modelUser : null;
     }
     return false;
 }
開發者ID:baranov-nt,項目名稱:setyes,代碼行數:26,代碼來源:RegForm.php

示例9: actionIndex

 /**
  * Lists all Acts models.
  * @return mixed
  */
 public function actionIndex()
 {
     $searchModel = new ActsSearch();
     $usr = User::findOne(Yii::$app->user->id);
     $dataProvider = $searchModel->search(Yii::$app->request->queryParams, $usr->_1c_id);
     return $this->render('index', ['searchModel' => $searchModel, 'dataProvider' => $dataProvider]);
 }
開發者ID:Griff19,項目名稱:altbur,代碼行數:11,代碼來源:ActsController.php

示例10: findOne

 /**
  * @param $id
  * @return $this
  */
 public function findOne($id)
 {
     $user = User::findOne($id);
     $this->username = $user->username;
     $this->email = $user->email;
     return $this;
 }
開發者ID:xuguoliangjj,項目名稱:datacenter,代碼行數:11,代碼來源:SignupForm.php

示例11: execute

 public function execute($user, $item, $params)
 {
     //Получаем массив пользователя из базы
     $cacheUser = 'User_role:' . Yii::$app->user->id;
     if (false === ($_user = Yii::$app->cache->get($cacheUser))) {
         if (null === ($_user = User::findOne($user))) {
             return FALSE;
             //throw new NotFoundHttpException;
         }
         Yii::$app->cache->set($cacheUser, $_user, 86400);
     }
     $user = ArrayHelper::getValue($params, 'user', $_user);
     if ($user) {
         $role = $user->role;
         //Значение из поля role базы данных
         if ($item->name === 'admin') {
             return $role == User::ROLE_ADMIN;
         } elseif ($item->name === 'moder') {
             //moder является потомком admin, который получает его права
             return $role == User::ROLE_ADMIN || $role == User::ROLE_MODER;
         } elseif ($item->name === 'user') {
             return $role == User::ROLE_ADMIN || $role == User::ROLE_MODER || $role == User::ROLE_USER;
         }
     }
     return false;
 }
開發者ID:Kulkow,項目名稱:mainsite,代碼行數:26,代碼來源:UserRoleRule.php

示例12: getUser

 /**
  * @return null|User
  */
 protected function getUser()
 {
     if ($this->_user === null) {
         $this->_user = User::findOne($this->user_id);
     }
     return $this->_user;
 }
開發者ID:aixiaobenaixiaoben,項目名稱:find,代碼行數:10,代碼來源:ActivateAccountForm.php

示例13: actionCreateEvent

 public function actionCreateEvent()
 {
     $model = new EventCreateForm();
     $model->own_id = \Yii::$app->user->getId();
     $model->create_at = date('Y-m-d h:i');
     if ($model->load(\Yii::$app->request->post())) {
         if (!$model->validate()) {
             return $this->render('error');
         }
         if (sizeof($model->friend) > 0) {
             $title = $model->title . ' (Member: ' . User::findOne(['id' => \Yii::$app->user->getId()])->username;
             foreach ($model->friend as $userId) {
                 $title = $title . ', ' . User::findOne(['id' => $userId])->username;
             }
             $title = $title . ')';
         } else {
             $title = $model->title;
         }
         $eventId = $model->addEvent($title);
         if (sizeof($model->friend) > 0) {
             foreach ($model->friend as $userId) {
                 $scheduleNotify = new ScheduleNotification();
                 $scheduleNotify['schedule_id'] = $eventId;
                 $scheduleNotify['receiver_id'] = $userId;
                 $scheduleNotify['action_id'] = \Yii::$app->user->getId();
                 $scheduleNotify['create_at'] = $model->create_at;
                 $scheduleNotify->save();
             }
         }
         $this->refresh();
     }
     return $this->render('show', ['model' => $model]);
 }
開發者ID:ockor,項目名稱:yii2adv-blog,代碼行數:33,代碼來源:ScheduleController.php

示例14: actionIndex

 public function actionIndex()
 {
     $user = \Yii::$app->user->identity;
     $parent = null;
     $child = null;
     if (!\Yii::$app->user->can('admin')) {
         $user->parent_id ? $parent = \common\models\User::findOne(['id' => $user->parent_id]) : '';
         $child = new \yii\data\ActiveDataProvider(['query' => \common\models\User::find()->where(['parent_id' => $user->id])]);
     } else {
         $userList = \common\models\User::find()->where(['parent_id' => null])->orderBy('id')->all();
         $tree = [];
         foreach ($userList as $key => $item) {
             $tree[] = $item;
             $branch = $this->makeTree($item->id, 0, array());
             $tree = array_merge($tree, $branch);
         }
         $userList = $tree;
         //            print_r('<pre>');
         //            print_r($userList);
         //            print_r('</pre>');
         //            die();
     }
     $crypt = openssl_encrypt($user->email, 'aes-128-ecb', '304c6528f659c77866a510d9c1d6ae5e', false);
     return $this->render('index', ['parent' => $parent, 'child' => $child, 'crypt' => $crypt, 'userList' => $userList]);
 }
開發者ID:lampyris,項目名稱:referral,代碼行數:25,代碼來源:SiteController.php

示例15: addRate

 /**
  * добавляет в базу новую ставку
  * @param Model $fantasy
  */
 public function addRate($fantasy)
 {
     $draftModel = new PokerDraft();
     $PokerDraftPlayer = new PokerDraftPlayer();
     $draftModel->attributes = $this->attributes;
     $draftModel->save();
     //echo'<pre>'; print_r($draftModel);echo'</pre>';die;
     $PokerDraftPlayer->addPlayersRows($this->players, $draftModel->id);
     //снимаем взнос+комиссия у игрока
     $user = User::findOne(Yii::$app->user->id);
     $deposit_before = $user->deposit;
     $user->deposit = $user->deposit - $fantasy->deposit - $fantasy->fee;
     if ($user->save()) {
         //заносим в лог
         $data = ['fantasy_id' => $fantasy->id, 'game' => Transaction::TR_GAME_POKER];
         $trans_descr = Transaction::buildTransactionDescrForSave(Transaction::TR_TYPE_FANTASY_PAYMENT, $data);
         Transaction::saveTransaction($user->id, $deposit_before, -($fantasy->deposit + $fantasy->fee), $trans_descr);
     }
     //если нужно - увеличиваем призовой фонд
     //$total_sum_rates = PokerDraft::getCountFantasyDrafts($fantasy->id) * $fantasy->deposit;
     $total_sum_rates = $draftModel->getCountFantasyDrafts($fantasy->id) * $fantasy->deposit;
     if ($total_sum_rates > $fantasy->prize_pool_real) {
         PokerFantasy::upateRealPrizePool($fantasy->id, $total_sum_rates);
     }
 }
開發者ID:aldegtyarev,項目名稱:fantasy,代碼行數:29,代碼來源:PokerDraftForm.php


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