add role to user
This commit is contained in:
@@ -3,15 +3,21 @@
|
||||
use yii\helpers\Html;
|
||||
use yii\widgets\ActiveForm;
|
||||
use yii\grid\GridView;
|
||||
use yii\base\Widget;
|
||||
use yii\base\Object;
|
||||
use yii\data\ArrayDataProvider;
|
||||
use common\components\RoleDefinition;
|
||||
|
||||
/* @var $this yii\web\View */
|
||||
/* @var $model common\models\User */
|
||||
/* @var $form yii\widgets\ActiveForm */
|
||||
?>
|
||||
|
||||
<?php
|
||||
|
||||
$roleOptions = RoleDefinition::roleLabels();
|
||||
asort($roleOptions);
|
||||
|
||||
?>
|
||||
|
||||
<div class="user-form">
|
||||
|
||||
<?php $form = ActiveForm::begin(); ?>
|
||||
@@ -21,6 +27,7 @@ use yii\data\ArrayDataProvider;
|
||||
<?= $form->field($model, 'email')->textInput() ?>
|
||||
<?= $form->field($model, 'password_plain')->passwordInput() ?>
|
||||
<?= $form->field($model, 'password_repeat')->passwordInput() ?>
|
||||
<?= $form->field($model, 'role')->dropDownList($roleOptions) ?>
|
||||
|
||||
<?php
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
use yii\helpers\Html;
|
||||
use yii\grid\GridView;
|
||||
use common\components\RoleDefinition;
|
||||
|
||||
/* @var $this yii\web\View */
|
||||
/* @var $searchModel frontend\models\UserSearch */
|
||||
@@ -28,6 +29,15 @@ $this->params['breadcrumbs'][] = $this->title;
|
||||
'email:email',
|
||||
'created_at:datetime',
|
||||
|
||||
[
|
||||
'attribute' => 'role',
|
||||
'value' => function ($model){
|
||||
$roles = \Yii::$app->authManager->getRolesByUser($model->id );
|
||||
|
||||
return implode(', ', array_map(function ($role) { return sprintf("%s", RoleDefinition::getRoleLabel($role->name)); }, $roles ));
|
||||
}
|
||||
] ,
|
||||
|
||||
['class' => 'yii\grid\ActionColumn',
|
||||
'template' => '{view} {update}'
|
||||
],
|
||||
|
||||
@@ -25,6 +25,10 @@ $this->params['breadcrumbs'][] = $this->title;
|
||||
'email:email',
|
||||
'statusHuman',
|
||||
'created_at:datetime',
|
||||
[
|
||||
'attribute' => 'role',
|
||||
'value' => $model->roleString
|
||||
]
|
||||
],
|
||||
]) ?>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user