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


PHP User::find方法代碼示例

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


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

示例1: actionLogin

 /**
  * 登錄控製
  * @return type
  */
 public function actionLogin()
 {
     if (!\Yii::$app->user->isGuest) {
         $this->redirect('/member/index.html');
     }
     $time = time();
     $time = $time - 10;
     if (!empty(\Yii::$app->request->get('id')) && !empty(\Yii::$app->request->get('stoken'))) {
         $user_id = \Yii::$app->request->get('id');
         $stoken = \Yii::$app->request->get('stoken');
         //$user = Users::model()->find(" user_id=:id AND repstaken=:repstaken AND repsativetime>=:time", array(":id"=>$user_id,":repstaken" => $stoken, ":time" => $time));
         //echo $user_id;exit;
         $user = User::find()->where(" user_id=:id", [":id" => $user_id])->one();
         //$user = User::model()->find(" user_id=:id", array(":id" => $user_id));
         if ($user) {
             $loginform = new LoginForm();
             $loginform->setAttributes(['username' => $user->username, 'password' => $user->password, 'rememberMe' => true]);
             if ($loginform->login(2)) {
                 $this->redirect('/member/index.html');
                 \Yii::$app->end();
             }
         }
     }
     $this->redirect('/public/nologin.html');
 }
開發者ID:wxzuan,項目名稱:wxzuan,代碼行數:29,代碼來源:PublicController.php

示例2: getUser

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

示例3: actionIndexadd

 public function actionIndexadd()
 {
     if (Yii::$app->user->isGuest) {
         $model = new LoginForm();
         if ($model->load(Yii::$app->request->post()) && $model->login()) {
             return $this->goBack();
         } else {
             return $this->render('/site/login', ['model' => $model]);
         }
     } else {
         $Order = new Order();
         $Order->user_id = Yii::$app->user->identity->id;
         $Order->date_time = date('Y-m-d H:i:s');
         $Order->status_id = '1';
         $Order->save();
         $Card = new CardList();
         $Products = $Card->getCardAndCardList(Yii::$app->user->identity->id);
         $Ord = new Order();
         $order_id = $Ord->GetOrderId(Yii::$app->user->identity->id);
         for ($i = 0; $i < sizeof($Products); $i++) {
             $Orderlist = new Orderlist();
             $Orderlist->order_id = $order_id[0]['MAX(`order_id`)'];
             $Orderlist->product_id = $Products[$i]['product_id'];
             $Orderlist->quantity = $Products[$i]['quantity'];
             $Orderlist->save();
         }
         $card = new Card();
         $card->DeleteCardId(Yii::$app->user->identity->id);
         $order = $Ord->GetOrdersFromID(Yii::$app->user->identity->id);
         $user = User::find()->where(['id' => Yii::$app->user->identity->id])->one();
         return $this->render('index', ['user' => $user, 'order' => $order]);
     }
 }
開發者ID:przemek207,項目名稱:Nzi_Project,代碼行數:33,代碼來源:AccountController.php

示例4: actionGetUserInfo

 public function actionGetUserInfo()
 {
     $user = wanhunet::$app->user;
     $userArray = User::find()->where(['id' => $user->id])->select(['username', 'id'])->asArray()->one();
     $userArray['role'] = current(wanhunet::$app->authManager->getRolesByUser($user->id));
     return $userArray;
 }
開發者ID:suyuanen,項目名稱:p2p,代碼行數:7,代碼來源:AuthController.php

示例5: actionCreate2

 public function actionCreate2()
 {
     $username = Yii::$app->user->identity->username;
     $users = User::find()->all();
     $scholars = Scholar::find()->all();
     $model2 = new Email();
     foreach ($users as $user) {
         foreach ($scholars as $scholar) {
             if ($user->username == $username && $user->id == $scholar->scholar_user_id) {
                 $model2->email_scholar_id = $scholar->scholar_id;
                 $model2->subject = "Low/Fail Grade";
                 if ($model2->load(Yii::$app->request->post())) {
                     if ($model->load(Yii::$app->request->post())) {
                         $to = "root@localhost.com";
                         $subject = "Low/Fail Grade";
                         $body = $model2->content . "\nfrom:" . $scholar->scholar_contact_email . PHP_EOL;
                         $headers = "from: root@localhost";
                         if (mail($to, $subject, $body, $headers)) {
                             \Yii::$app->getSession()->setFlash('error', 'The message is delivered');
                         } else {
                             \Yii::$app->getSession()->setFlash('error', 'Message failed');
                         }
                         return $this->redirect(['subject/index', 'id' => $model2->email_id]);
                         return $this->redirect(['create2', 'id' => $model2->email_id]);
                     } else {
                         return $this->render('create2', ['model2' => $model2]);
                     }
                 }
             }
         }
     }
 }
開發者ID:seans888,項目名稱:SMF-Project,代碼行數:32,代碼來源:EmailController.php

示例6: actionSubscriptionUserNotifications

 /**
  * Уведомления при подписке на человека
  */
 public function actionSubscriptionUserNotifications()
 {
     $date_minus_six_hours = new \DateTime();
     $date_minus_six_hours = $date_minus_six_hours->modify('-2 hours');
     $email_queue = [];
     $wall_events = Wall::find()->where('created >= ' . $date_minus_six_hours->getTimestamp() . ' AND created <= ' . time())->all();
     foreach ($wall_events as $event) {
         if ($event->type == 2) {
             $event_data = json_decode($event->mem);
             $User = User::findOne(['id' => $event_data->to]);
             $Subscriber = User::find()->where(['id' => $event_data->from])->asArray()->one();
             if ($Subscriber) {
                 $email_queue[$User->email][$event_data->from] = ['subscriber' => User::find()->where(['id' => $event_data->from])->asArray()->one(), 'data' => $event->created, 'status' => $event_data->status];
             }
         }
     }
     foreach ($email_queue as $email => $recipient) {
         $subscribed = [];
         $unsubscribed = [];
         foreach ($recipient as $person) {
             if ($person['status']) {
                 $subscribed[] = $person;
             } else {
                 $unsubscribed[] = $person;
             }
         }
         $messages[] = \Yii::$app->mailer->compose('user-subscribe', ['subscribed' => $subscribed, 'unsubscribed' => $unsubscribed])->setFrom('noreply@findspree.ru')->setTo($email)->setSubject('Для Вас есть новые уведомления на сайте http://findspree.ru');
     }
     if (isset($messages) && !empty($messages)) {
         \Yii::$app->mailer->sendMultiple($messages);
     }
 }
開發者ID:KPEMATOP,項目名稱:findspree_old,代碼行數:35,代碼來源:MailController.php

示例7: search

 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = User::find()->joinWith('authAssignment.authItem');
     $pageSize = isset($_GET['per-page']) ? $_GET['per-page'] : \Yii::$app->params['user.defaultPageSize'];
     // Aca se cocina lo que deberia ver el usuario segun su rol
     $rol = User::getRol(Yii::$app->user->getId());
     // el administrador no puede ver al usuario consejo, el consejo puede ver a todos,
     // el intendente no puede ver al consejo ni administrador
     switch ($rol->name) {
         case (string) "administrador":
             $query->andFilterWhere(['not in', 'item_name', ['consejo']]);
             break;
         case (string) "consejo":
             break;
         case (string) "intendente":
             $query->andFilterWhere(['not in', 'item_name', ['administrador', 'consejo']]);
             break;
         default:
             $query->andFilterWhere(['not in', 'item_name', ['intendente', 'administrador', 'consejo']]);
     }
     $query->andFilterWhere(['status' => User::STATUS_ACTIVE]);
     $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ['pageSize' => $pageSize], 'sort' => ['defaultOrder' => ['id' => SORT_DESC], 'enableMultiSort' => true]]);
     // Agregado a mano, para que incluya el ordenamiento por descCliente
     $dataProvider->sort->attributes['descRolUsuario'] = ['asc' => ['auth_item.description' => SORT_ASC], 'desc' => ['auth_item.description' => SORT_DESC]];
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to return any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'status' => $this->status, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at, 'acceso_externo' => $this->acceso_externo]);
     $query->andFilterWhere(['like', 'username', $this->username])->andFilterWhere(['like', 'email', $this->email])->andFilterWhere(['like', 'auth_item.description', $this->descRolUsuario]);
     return $dataProvider;
 }
開發者ID:ibergonzi,項目名稱:country,代碼行數:41,代碼來源:UserSearch.php

示例8: getUser

 /**
  * Finds user by [[username]]
  *
  * @return User|null
  */
 public function getUser()
 {
     if ($this->user === false) {
         $this->user = User::find()->activated()->notDeleted()->andWhere(['or', ['username' => $this->identity], ['email' => $this->identity]])->one();
     }
     return $this->user;
 }
開發者ID:icron,項目名稱:yii2-starter-kit,代碼行數:12,代碼來源:LoginForm.php

示例9: actionList

 /**
  * Список пользователей в компании.
  *
  * @return string
  */
 public function actionList()
 {
     /** @var \common\models\User $user */
     $user = Yii::$app->getUser()->getIdentity();
     $users = User::find()->where('user_id!=:user_id and company_id=:company_id and is_deleted=0', ['user_id' => $user->getId(), 'company_id' => $user->getCompanyId()])->all();
     return $this->render('list', ['users' => $users]);
 }
開發者ID:vlamug,項目名稱:landing-page-crm,代碼行數:12,代碼來源:UserController.php

示例10: getUser

 /**
  * Finds user by [[username]] or [[id]].
  *
  * @return User|null
  */
 protected function getUser()
 {
     if ($this->user === null) {
         $this->user = User::find()->andWhere(['and', ['or', ['username' => $this->identity], ['email' => $this->identity]]])->active()->one();
     }
     return $this->user;
 }
開發者ID:beaten-sect0r,項目名稱:yii2-core,代碼行數:12,代碼來源:LoginForm.php

示例11: search

 /**
  * Creates data provider instance with search query applied
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = User::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     // Important: here is how we set up the sorting
     // The key is the attribute name on our "TourSearch" instance
     $dataProvider->sort->attributes['search_date_created'] = ['asc' => ['created_at' => SORT_ASC], 'desc' => ['created_at' => SORT_DESC]];
     // Important: here is how we set up the sorting
     // The key is the attribute name on our "TourSearch" instance
     $dataProvider->sort->attributes['search_date_logged'] = ['asc' => ['logged_at' => SORT_ASC], 'desc' => ['logged_at' => SORT_DESC]];
     if (!($this->load($params) && $this->validate())) {
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'status' => $this->status, 'domain_id' => $this->domain_id]);
     if ($this->search_date_created != '') {
         $this->data_begin_created = strtotime($this->search_date_created);
         $this->data_end_created = strtotime($this->search_date_created) + 24 * 60 * 60;
     }
     if ($this->search_date_logged != '') {
         $this->data_begin_logged = strtotime($this->search_date_logged);
         $this->data_end_logged = strtotime($this->search_date_logged) + 24 * 60 * 60;
     }
     $query->andFilterWhere(['like', 'username', $this->username])->andFilterWhere(['like', 'auth_key', $this->auth_key])->andFilterWhere(['like', 'password_hash', $this->password_hash])->andFilterWhere(['like', 'password_reset_token', $this->password_reset_token])->andFilterWhere(['between', 'created_at', $this->data_begin_created, $this->data_end_created])->andFilterWhere(['between', 'logged_at', $this->data_begin_logged, $this->data_end_logged])->andFilterWhere(['like', 'email', $this->email]);
     return $dataProvider;
 }
開發者ID:efabrikov,項目名稱:renault,代碼行數:29,代碼來源:UserSearch.php

示例12: signup1

 /**
  * Signs user up.
  *
  * @return User|null the saved model or null if saving fails
  */
 public function signup1()
 {
     if ($this->validate()) {
         $user = new user();
         $user->username = $this->email;
         $user->email = $this->email;
         $user->firstname = $this->fname;
         $user->lastname = $this->lname;
         $user->setPassword($this->password);
         $user->generateAuthKey();
         if ($user->save()) {
             \Yii::$app->mailer->compose(['html' => 'auth-html'], ['user' => $user])->setFrom([\Yii::$app->params['supportEmail'] => \Yii::$app->name . ' robot'])->setTo($this->email)->setSubject('Authenticate your account ' . \Yii::$app->name)->send();
             $date = Yii::$app->formatter->asDatetime(date('Y-d-m h:i:s'));
             $car = new Car();
             //$model_name=$this->$model_name;
             $row = Car::find()->where('model=:model AND model_name=:model_name AND fuel=:fuel AND variant=:variant', array(':model' => $this->brand, ':model_name' => $this->model_name, 'fuel' => $this->fuel, 'variant' => $this->variant))->one();
             $user = User::find()->where('email=:email', array(':email' => $this->email))->one();
             $urequest = new Userrequest();
             $urequest->car_id = $row->id;
             $urequest->user_id = $user->id;
             $urequest->color = $this->color;
             $urequest->city = $this->city;
             $urequest->other = $this->other;
             $urequest->delivery = $this->delivery;
             $urequest->status = 0;
             $urequest->time = $date;
             if ($urequest->save()) {
                 return $user;
             }
         } else {
             return null;
         }
     }
 }
開發者ID:vaibhavk01,項目名稱:motor,代碼行數:39,代碼來源:Chatform.php

示例13: search

 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = User::find();
     $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => array('pageSize' => 2)]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to return any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->joinWith('usertype');
     if (isset($params['UserSearch']['search']) && $params['UserSearch']['search'] != '') {
         if ($params['UserSearch']['field'] == '') {
             $query->orFilterWhere(['=', 'user.id', $params['UserSearch']['search']])->orFilterWhere(['=', 'user.status', $params['UserSearch']['search']])->orFilterWhere(['like', 'user.first_name', $params['UserSearch']['search']])->orFilterWhere(['like', 'user.last_name', $params['UserSearch']['search']])->orFilterWhere(['like', 'user.email', $params['UserSearch']['search']])->orFilterWhere(['like', 'user.created_at', $params['UserSearch']['search']])->orFilterWhere(['like', 'user_type.title', $params['UserSearch']['search']])->orFilterWhere(['like', 'user.username', $params['UserSearch']['search']]);
         } else {
             if ($params['UserSearch']['field'] == 'id' || $params['UserSearch']['field'] == 'status') {
                 $query->andFilterWhere(['=', 'user.' . $params['UserSearch']['field'], $params['UserSearch']['search']]);
             } elseif ($params['UserSearch']['field'] == 'user_type_id') {
                 $query->andFilterWhere(['like', 'user_type.title', $params['UserSearch']['search']]);
             } else {
                 $query->andFilterWhere(['like', 'user.' . $params['UserSearch']['field'], $params['UserSearch']['search']]);
             }
         }
     } else {
         $query->andFilterWhere(['id' => $this->id, 'status' => $this->status, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at]);
         $query->andFilterWhere(['like', 'first_name', $this->first_name])->andFilterWhere(['like', 'last_name', $this->last_name])->andFilterWhere(['like', 'username', $this->username])->andFilterWhere(['like', 'email', $this->email])->andFilterWhere(['like', 'user_type.title', $this->user_type_id]);
     }
     return $dataProvider;
 }
開發者ID:sunil120,項目名稱:yii2,代碼行數:36,代碼來源:UserSearch.php

示例14: actionIndex

 public function actionIndex()
 {
     if (Yii::$app->user->isGuest) {
         $model = new LoginForm();
         if ($model->load(Yii::$app->request->post()) && $model->login()) {
             return $this->goBack();
         } else {
             return $this->render('/site/login', ['model' => $model]);
         }
     } else {
         if (!empty($_POST)) {
             $model = new User();
             $model = User::find()->where(['id' => Yii::$app->user->identity->id])->one();
             //$model->username = '$_POST['username']';
             //$model->email = '$_POST['email']';
             $model->country = $_POST['country'];
             $model->city = $_POST['city'];
             $model->street = $_POST['street'];
             $model->zip_code = $_POST['zip_code'];
             $model->save();
         }
         $user = User::find()->where(['id' => Yii::$app->user->identity->id])->one();
         return $this->render('index', ['user' => $user]);
     }
 }
開發者ID:keszfeayym,項目名稱:Nzi_Project,代碼行數:25,代碼來源:AccountController.php

示例15: notification

 public function notification($event)
 {
     $model = User::find()->where(['roles' => 'admin'])->all();
     foreach ($model as $r) {
         Common::sendMail();
     }
 }
開發者ID:pers1307,項目名稱:yii,代碼行數:7,代碼來源:Subscribe.php


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