当前位置: 首页>>代码示例>>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;未经允许,请勿转载。