本文整理汇总了PHP中common\models\User::getRole方法的典型用法代码示例。如果您正苦于以下问题:PHP User::getRole方法的具体用法?PHP User::getRole怎么用?PHP User::getRole使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类common\models\User
的用法示例。
在下文中一共展示了User::getRole方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: login
/**
* Logs in a user using the provided username and password.
*
* @return boolean whether the user is logged in successfully
*/
public function login()
{
/** @var User $user */
$user = $this->getUser();
if ($this->validate() && isset(User::getRole($user->id)['admin'])) {
return Yii::$app->user->login($user, $this->rememberMe ? 3600 * 24 * 30 : 0);
} else {
return false;
}
}
示例2: function
use yii\grid\GridView;
/* @var $this yii\web\View */
/* @var $searchModel common\models\UserSearch */
/* @var $dataProvider yii\data\ActiveDataProvider */
$this->title = 'Users';
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="user-index">
<h1><?php
echo Html::encode($this->title);
?>
</h1>
<?php
// echo $this->render('_search', ['model' => $searchModel]);
?>
<p>
<?php
echo Html::a('Create User', ['create'], ['class' => 'btn btn-success']);
?>
</p>
<?php
echo GridView::widget(['dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'columns' => [['class' => 'yii\\grid\\SerialColumn'], 'id', 'username', 'avatar', ['attribute' => 'role', 'value' => function ($model) {
return User::getRole($model->role)['name'];
}], 'created_at:datetime', 'updated_at:datetime', ['class' => 'yii\\grid\\ActionColumn']]]);
?>
</div>
示例3: json_encode
use yii\grid\GridView;
use yii\helpers\Url;
/* @var $this yii\web\View */
/* @var $searchModel common\models\UserSearch */
/* @var $dataProvider yii\data\ActiveDataProvider */
$this->title = Yii::t('user', 'List users');
?>
<div class="user-index">
<br>
<?php
echo GridView::widget(['dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'columns' => [['class' => 'yii\\grid\\SerialColumn'], ['attribute' => 'email', 'format' => 'raw', 'value' => function ($data) {
return Html::a($data->email, Url::to(['update', 'id' => $data->id]));
}], ['class' => \dosamigos\grid\EditableColumn::className(), 'filter' => User::statuses(), 'attribute' => 'status', 'url' => ['ajaxUpdate'], 'type' => 'select', 'display' => "colors", 'editableOptions' => function ($model) {
return ['source' => User::statuses(), 'value' => $model->status];
}], ['class' => \dosamigos\grid\EditableColumn::className(), 'filter' => User::roles(), 'attribute' => 'role', 'url' => ['ajaxUpdate'], 'value' => function ($data) {
return User::getRole($data->role);
}, 'type' => 'select', 'display' => "function(value,sourceData,response){console.log(sourceData);}", 'editableOptions' => ['source' => Yii::$app->user->identity->getEditableRoles(), 'sourceCache' => false]], ['attribute' => 'created_at', 'filter' => false, 'format' => 'datetime'], ['attribute' => 'updated_at', 'filter' => false, 'format' => 'datetime'], ['class' => 'yii\\grid\\ActionColumn']]]);
?>
</div>
<script>
function colors(value, sourceData) {
var selected = $.grep(sourceData, function (o) {
return value == o.value;
}),
colors = <?php
echo json_encode(User::$status_colors);
?>
;
$(this).html(selected[0].text).css("color", colors[value]);
}
示例4:
</div>
<div class="media-body">
<h2 class="mt5"><?php
echo Html::tag('strong', Html::encode($user->username));
?>
</h2>
<p>第 <?php
echo $user->id;
?>
位会员</p>
<div class="pull-left">
<span class="label label-<?php
echo User::getRole($user->role)['color'];
?>
role"><?php
echo User::getRole($user->role)['name'];
?>
</span>
</div>
</div>
</div>
<div class="follow-info row">
<div class="col-sm-4 followers" data-login="rei">
<a class="counter" href="<?php
echo Url::to(['/user/default/point', 'username' => $username]);
?>
">
<?php
echo $user->merit ? $user->merit->merit : 0;
?>
示例5: fillUserData
/**
* Заполнение данных пользователя.
*
* @param User $user
*/
public function fillUserData(User $user)
{
$this->setUserId($user->getId());
$this->setCompanyId($user->getCompanyId());
$this->setEmail($user->getEmail());
$this->setFullName($user->getFullName());
$this->setRole($user->getRole());
$this->setStatus($user->getStatus());
$this->setPhoto($user->getPhoto());
}