当前位置: 首页>>代码示例>>PHP>>正文


PHP User::findOne方法代码示例

本文整理汇总了PHP中dektrium\user\models\User::findOne方法的典型用法代码示例。如果您正苦于以下问题:PHP User::findOne方法的具体用法?PHP User::findOne怎么用?PHP User::findOne使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在dektrium\user\models\User的用法示例。


在下文中一共展示了User::findOne方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: safeDown

 public function safeDown()
 {
     $controller = Yii::$app->controller;
     $model = \Yii::createObject(LoginForm::className());
     do {
         if ($model->hasErrors()) {
             $this->showErrors($model);
         }
         // get username
         $username = $controller->prompt($controller->ansiFormat("\tUsername: ", \yii\helpers\Console::FG_BLUE));
         // get password
         echo $controller->ansiFormat("\tPassword: ", \yii\helpers\Console::FG_BLUE);
         system('stty -echo');
         $password = trim(fgets(STDIN));
         system('stty echo');
         echo "\n";
         $model->login = $username;
         $model->password = $password;
     } while (!$model->validate());
     $user = User::findOne(['username' => $username]);
     if (empty($user)) {
         throw new \yii\console\Exception("Unable to find user {$username}");
     }
     $this->delete('{{%auth_assignment}}', ['item_name' => 'admin', 'user_id' => $user->primaryKey]);
     $user->delete();
 }
开发者ID:hector-del-rio,项目名称:yii2-attache,代码行数:26,代码来源:m150805_191756_yii2user_add_admin_user.php

示例2: findModel

 protected function findModel($id)
 {
     if (($model = User::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
开发者ID:kapilbhadke,项目名称:ConnectMe,代码行数:8,代码来源:ConnectMeUserController.php

示例3: actionAssign

 public function actionAssign($role, $userId)
 {
     $user = User::findOne($userId);
     if (!$user) {
         throw new InvalidParamException('There is no such user.');
     }
     $auth = Yii::$app->authManager;
     $role = $auth->getRole($role);
     if (!$role) {
         throw new InvalidParamException('There is no such role.');
     }
     $auth->assign($role, $userId);
 }
开发者ID:romaten1,项目名称:yourjob,代码行数:13,代码来源:RbacController.php

示例4: search

 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Ruta::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $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;
     }
     $user = User::findOne(['username' => $this->id_usuario]);
     $query->andFilterWhere(['id' => $this->id]);
     if ($this->id_usuario != null) {
         $query->andFilterWhere(['id_usuario' => $user != null ? $user->id : 0]);
     }
     if (strtolower($this->esActivo) == strtolower(Yii::t('core', 'Yes'))) {
         $query->andFilterWhere(['esActivo' => $this->esActivo == 0]);
     } else {
         if (strtolower($this->esActivo) == strtolower(Yii::t('core', 'No'))) {
             $query->andFilterWhere(['esActivo' => $this->esActivo == 1]);
         }
     }
     if (strtolower($this->dia) == strtolower(Yii::t('core', 'Monday'))) {
         $query->andFilterWhere(['dia' => 1]);
     } else {
         if (strtolower($this->dia) == strtolower(Yii::t('core', 'Tuesday'))) {
             $query->andFilterWhere(['dia' => 2]);
         } else {
             if (strtolower($this->dia) == strtolower(Yii::t('core', 'Wednesday'))) {
                 $query->andFilterWhere(['dia' => 3]);
             } else {
                 if (strtolower($this->dia) == strtolower(Yii::t('core', 'Thursday'))) {
                     $query->andFilterWhere(['dia' => 4]);
                 } else {
                     if (strtolower($this->dia) == strtolower(Yii::t('core', 'Friday'))) {
                         $query->andFilterWhere(['dia' => 5]);
                     } else {
                         if (strtolower($this->dia) == strtolower(Yii::t('core', 'Saturday'))) {
                             $query->andFilterWhere(['dia' => 6]);
                         } else {
                             if (strtolower($this->dia) == strtolower(Yii::t('core', 'Sunday'))) {
                                 $query->andFilterWhere(['dia' => 7]);
                             }
                         }
                     }
                 }
             }
         }
     }
     return $dataProvider;
 }
开发者ID:apmauj,项目名称:1f8bf10ab74d6f5ca69f7c07b7ee1c38,代码行数:58,代码来源:RutaSearch.php

示例5: testRegister

 public function testRegister()
 {
     $this->model = new RegistrationForm();
     $this->model->setAttributes(['email' => 'foobar@example.com', 'username' => 'foobar', 'password' => 'foobar']);
     /** @var User $user */
     verify($this->model->register())->true();
     $user = User::findOne(['email' => 'foobar@example.com']);
     verify('$user is instance of User', $user instanceof User)->true();
     verify('email is valid', $user->email)->equals($this->model->email);
     verify('username is valid', $user->username)->equals($this->model->username);
     verify('password is valid', Password::validate($this->model->password, $user->password_hash))->true();
     $token = Token::findOne(['user_id' => $user->id, 'type' => Token::TYPE_CONFIRMATION]);
     verify($token)->notNull();
     $mock = $this->getMock(RegistrationForm::className(), ['validate']);
     $mock->expects($this->once())->method('validate')->will($this->returnValue(false));
     verify($mock->register())->false();
 }
开发者ID:manyoubaby123,项目名称:imshop,代码行数:17,代码来源:RegistrationFormTest.php

示例6: addUserHistory

 public static function addUserHistory($serverId)
 {
     $server = \common\models\GameServer::findOne($serverId);
     $game = $server->getGame()->one();
     $user = \Yii::$app->user->identity;
     $user = User::findOne(2);
     $userHistory = new UserHistory();
     $userHistory->user_id = $user->getId();
     $userHistory->game_id = $server->game_id;
     $userHistory->server_id = $server->id;
     $userHistory->status = UserHistory::STATUS_IN_USE;
     if ($userHistory->save()) {
         return $userHistory;
     } else {
         return null;
     }
 }
开发者ID:buuug7,项目名称:game4039,代码行数:17,代码来源:Buuug7Util.php

示例7: actionIndex

 public function actionIndex()
 {
     $params = Yii::$app->request->queryParams;
     $tab = isset($params['tab']) ? $params['tab'] : 0;
     $bmodel = new BasketSearch();
     $bdataProvider = $bmodel->search([]);
     $user = \Yii::$app->user->isGuest ? new User() : User::findOne(['id' => Yii::$app->user->id]);
     if ($bdataProvider->totalCount) {
         $itogo = $this->summa($bdataProvider, ['tovar_summa']);
         $basketContent = $this->renderPartial('basket_tab', ['model' => $bdataProvider, 'itogo' => $itogo]);
     } else {
         $basketContent = $this->renderPartial('not_tovar');
     }
     $profile = Yii::$app->user->isGuest ? new Profile() : Profile::findOne(['user_id' => Yii::$app->user->id]);
     $cityCode = Yii::$app->request->cookies['city'];
     $city = \app\modules\city\models\CitySearch::find()->where(['id' => $cityCode ? $cityCode : 2097])->one();
     $stores = new \app\modules\autoparts\models\TStoreSearch();
     $stores = $stores->search([':city_id' => $cityCode]);
     $user_tab_data = ['city' => $city, 'profile' => $profile, 'user' => $user];
     $delivery_tab_data = ['stores' => $stores];
     return $this->render('index', ['basketContent' => $basketContent, 'user_data' => $user_tab_data, 'delivery_data' => $delivery_tab_data, 'tab' => $tab]);
 }
开发者ID:kd-brinex,项目名称:kd,代码行数:22,代码来源:BasketController.php

示例8: ldap

 public function ldap()
 {
     $authen = false;
     $ua = base64_encode($_SERVER['HTTP_USER_AGENT']);
     $apiKey = Yii::$app->params['apiKey'];
     $password = base64_encode(md5($this->password));
     $url = Yii::$app->params['authUrl'] . "/{$ua}/{$apiKey}/{$password}/{$this->username}/json";
     $ldap = json_decode(Curl::getData($url));
     if (isset($ldap->success) && $ldap->success) {
         $user = User::findOne(['username' => $this->username]);
         if (empty($user) || $user === null) {
             if ($this->allowAddUser) {
                 $this->addUser($ldap);
             }
         } else {
             User::updateAll(['password_hash' => Password::hash($this->password)], ['username' => $this->username]);
         }
         if ($this->db()) {
             $authen = true;
         }
     }
     return $authen;
 }
开发者ID:pipekung,项目名称:classes,代码行数:23,代码来源:Auth.php

示例9: isset

$this->params['breadcrumbs'][] = $this->title;
$exceptField = ['created_at', 'updated_at', 'created_by', 'updated_by'];
$params = isset($params) ? $params : Yii::$app->request->get();
$query = isset($query) ? $query : null;
$columns = isset($columns) ? $columns : [];
$filter = isset($filter) ? $filter : true;
$this->registerAssetBundle(AuditAsset::className());
$auditTrailSearch = new AuditTrailSearch();
$auditTrailDataProvider = $auditTrailSearch->search($params, $query);
$auditTrailDataProvider->pagination = ['pageSize' => 10, 'pageParam' => 'page-auditTrails'];
$auditTrailDataProvider->sort = ['defaultOrder' => ['id' => SORT_DESC]];
$_columns = [];
if (empty($columns) || in_array('user_id', $columns)) {
    $_columns[] = ['attribute' => 'user_id', 'value' => function ($data) {
        $user_id = Audit::getInstance()->getUserIdentifier($data->user_id);
        $user = \dektrium\user\models\User::findOne($user_id);
        return '<h4><span class="label label-info">' . ($user ? $user->username : '员工本人') . '</span></h4>';
    }, 'format' => 'raw'];
}
if (empty($columns) || in_array('entry_id', $columns)) {
    $_columns[] = ['attribute' => 'entry_id', 'value' => function ($model) {
        /** @var AuditTrail $model */
        if (Access::checkAccess()) {
            return Html::a('<h4><span class="label label-success">' . $model->entry_id . '</span></h4>', ['/audit/entry/view', 'id' => $model->entry_id]);
        }
        return '<h4><span class="label label-success">' . $model->entry_id . '</span></h4>';
    }, 'format' => 'raw'];
}
if (empty($columns) || in_array('action', $columns)) {
    //$_columns[] = 'action';
    $_columns[] = ['attribute' => 'action', 'value' => function ($model) {
开发者ID:tqsq2005,项目名称:Yii2adv,代码行数:31,代码来源:_audit_trails.php

示例10: function

    <h1><?php 
echo Html::encode($this->title);
?>
</h1>
    <?php 
// echo $this->render('_search', ['model' => $searchModel]);
?>

    <p>
        <?php 
echo Html::a(Yii::t('core', 'Create Route'), ['create'], ['class' => 'btn btn-success']);
?>
    </p>

    <?php 
echo GridView::widget(['dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'columns' => [['class' => 'yii\\grid\\SerialColumn'], 'id', ['attribute' => 'dia', 'label' => Yii::t('core', "Day"), 'format' => 'raw', 'value' => function ($data) {
    return Yii::t('core', sysconfigs::getNombreDia($data->dia));
}], ['attribute' => 'esActivo', 'label' => Yii::t('core', 'Active?'), 'format' => 'raw', 'value' => function ($data) {
    if ($data->esActivo == 0) {
        return '<span class="label label-danger">' . Yii::t('core', sysconfigs::getNombreEsActivo($data->esActivo)) . '</span>';
    } else {
        return '<span class="label label-success">' . Yii::t('core', sysconfigs::getNombreEsActivo($data->esActivo)) . '</span>';
    }
}], ['attribute' => 'id_usuario', 'label' => Yii::t('core', 'User'), 'format' => 'raw', 'value' => function ($data) {
    return $usuario = User::findOne($data->id_usuario)->username;
}], ['header' => 'Options', 'class' => 'yii\\grid\\ActionColumn', 'template' => '{info} {view} {update} ']]]);
?>

</div>
开发者ID:apmauj,项目名称:1f8bf10ab74d6f5ca69f7c07b7ee1c38,代码行数:29,代码来源:index.php

示例11:

use yii\widgets\LinkPager;
use yii\bootstrap\Collapse;
use yii\bootstrap\Modal;
/* @var $this yii\web\View */
$this->title = $model->name;
?>
<div class="row" style="padding-top: 10%;">
    <div class="col-md-12 blog-column">
        <div class="card-panel bl-panel text-center hoverable">
            <?php 
$link_user = '<h4 class="black-text">' . $model->name . '<i class="material-icons"></i></h4>';
echo Html::a($link_user, ['content/viewsingle', 'id' => $model->id]);
?>
            <h6>Added by
                <a href="#"><?php 
echo \dektrium\user\models\User::findOne(['id' => $model->uploadedBy])->username;
?>
                </a>
                | 21.10.2015
            </h6>
            <hr>
            <div>

                <p class="text-center">
                    <?php 
if ($model->type == 'video') {
    ?>
                        <video id="video" width="80%" height="80%" poster="" controls>
                            <source src="<?php 
    echo Url::base();
    ?>
开发者ID:KhemPoudel,项目名称:onlinePaathsaala,代码行数:31,代码来源:singlecontent.php

示例12: actionIndex

 /**
  * (string) actionIndex :
  * @param $user_id
  * @return string
  */
 public function actionIndex($user_id)
 {
     /** @var User $user */
     $user = User::findOne($user_id);
     return $this->render('index', ['user' => $user]);
 }
开发者ID:tqsq2005,项目名称:Yii2adv,代码行数:11,代码来源:MapUnitController.php

示例13: login

 /**
  * Log in with username
  *
  * @param $username
  */
 private function login($username)
 {
     $user = User::findOne(['username' => $username]);
     \Yii::$app->user->login($user);
 }
开发者ID:dmstr,项目名称:yii2-db,代码行数:10,代码来源:ModelTest.php

示例14:

/* @var $model app\modules\admin\modules\rbac\models\AuthAssignment */
/* @var $form yii\widgets\ActiveForm */
?>

<div class="auth-assignment-form">

    <?php 
$form = ActiveForm::begin();
?>

    <?php 
echo $form->field($model, 'item_name')->dropDownList(AuthItem::getAuthItemArray(), ['prompt' => 'Виберіть роль ...']);
?>

    <?php 
echo !empty($model->user_id) ? '<p><b>Користувач: ' . User::findOne($model->user_id)->username . '</b></p>' : '';
?>
    <?php 
if (!empty($model->user_id)) {
    $user = AuthAssignment::find()->where(['user_id' => $model->user_id])->one();
    $role = $user->item_name;
    echo '<p><b>Поточна роль: ';
    if (!empty($role) && $model->isNewRecord) {
        echo $role . '</b></p>';
        echo 'Роль уже задано для цього користувача! краще змініть існуючу ' . Html::a('Редагувати роль', ['/rbac/auth-assignment/update', 'user_id' => $user->user_id, 'item_name' => $user->item_name], ['class' => 'btn btn-xl btn-danger']);
    } else {
        echo $role ? $role : 'Роль відсутня</b></p>';
        echo $form->field($model, 'user_id')->textInput(['maxlength' => 64]);
        echo '<div class="form-group">';
        echo Html::submitButton($model->isNewRecord ? 'Створити' : 'Оновити', ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']);
    }
开发者ID:romaten1,项目名称:yourjob,代码行数:31,代码来源:_form.php

示例15:

<?php

use yii\helpers\Html;
?>


    <!--1 Coulm horizontal listing-->
    <div class="card-panel horizontal-listing no-padding search-class">
        <div class="container-fluid">
            <h4 class="black-text"><?php 
echo $callerType;
?>
<i class="material-icons"></i></h4>
            <h5 class="black-text"><?php 
echo '(', \dektrium\user\models\User::findOne($caller)->username, ')';
?>
</h5>
            <hr>
            <?php 
foreach ($models as $model) {
    //$faculties=\common\models\faculty\FacultyRecord::find()->where(['university_id'=>$model->id]);
    ?>
                <div id="follow-div-<?php 
    echo $model->id;
    ?>
">
                <a>
                    <div class="row hoverable">
                        <div class="col-sm-4">
                            <img src="http://mdbootstrap.com/images/reg/reg%20(54).jpg" class="img-responsive z-depth-2">
                        </div>
开发者ID:KhemPoudel,项目名称:onlinePaathsaala,代码行数:31,代码来源:index.php


注:本文中的dektrium\user\models\User::findOne方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。