/** * @inheritdoc */ public function rules() { return [['username', 'trim'], ['username', 'required'], ['username', 'match', 'pattern' => '#^[\\w_-]+$#i'], ['username', 'unique', 'targetClass' => User::className(), 'filter' => function ($query) { if (!$this->getModel()->isNewRecord) { $query->andWhere(['not', ['id' => $this->getModel()->id]]); } }], ['username', 'string', 'min' => 2, 'max' => 32], ['email', 'trim'], ['email', 'required'], ['email', 'email'], ['email', 'unique', 'targetClass' => User::className(), 'filter' => function ($query) { if (!$this->getModel()->isNewRecord) { $query->andWhere(['not', ['id' => $this->getModel()->id]]); } }], ['email', 'string', 'max' => 255], ['password', 'required', 'on' => 'create'], ['password', 'string', 'min' => 6, 'max' => 32], ['status', 'integer'], ['status', 'in', 'range' => array_keys(User::statuses())], ['roles', 'each', 'rule' => ['in', 'range' => ArrayHelper::getColumn(Yii::$app->authManager->getRoles(), 'name')]]]; }
use common\models\User; use yii\helpers\Html; 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); ?> ;
<div class="user-form"> <?php $form = ActiveForm::begin(); ?> <?php echo $form->field($model, 'username'); ?> <?php echo $form->field($model, 'email'); ?> <?php echo $form->field($model, 'password')->passwordInput(); ?> <?php echo $form->field($model, 'status')->dropDownList(User::statuses()); ?> <?php echo $form->field($model, 'roles')->checkboxList($roles); ?> <div class="form-group"> <?php echo Html::submitButton(Yii::t('backend', 'Save'), ['class' => 'btn btn-primary', 'name' => 'signup-button']); ?> </div> <?php ActiveForm::end(); ?> </div>
?> <?php echo $form->field($user, 'username')->textInput(['maxlength' => true]); ?> <?php echo $form->field($user, 'password')->passwordInput(['maxlength' => true]); ?> <?php echo $form->field($user, 'email')->textInput(['maxlength' => true]); ?> <?php echo $form->field($user, 'status')->label(Yii::t('backend', 'Status'))->radioList(User::statuses()); ?> <?php echo $form->field($user, 'roles')->checkboxList($roles); ?> <?php echo $form->field($profile, 'firstname')->textInput(['maxlength' => true]); ?> <?php echo $form->field($profile, 'lastname')->textInput(['maxlength' => true]); ?> <?php
<?php use common\grid\EnumColumn; use common\models\User; use yii\helpers\Html; use yii\grid\GridView; /* @var $this yii\web\View */ /* @var $searchModel backend\models\search\UserSearch */ /* @var $dataProvider yii\data\ActiveDataProvider */ $this->title = Yii::t('backend', 'Users'); $this->params['breadcrumbs'][] = $this->title; ?> <div class="user-index"> <?php // echo $this->render('_search', ['model' => $searchModel]); ?> <p> <?php echo Html::a(Yii::t('backend', 'Create {modelClass}', ['modelClass' => 'User']), ['create'], ['class' => 'btn btn-success']); ?> </p> <?php echo GridView::widget(['dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'columns' => ['id', 'username', 'email:email', ['class' => EnumColumn::className(), 'attribute' => 'status', 'enum' => User::statuses(), 'filter' => User::statuses()], 'created_at:datetime', 'logged_at:datetime', ['class' => 'yii\\grid\\ActionColumn']]]); ?> </div>
use yii\bootstrap\Html; use yii\grid\GridView; use common\models\User; /* @var $this yii\web\View */ /* @var $searchModel backend\models\search\UserSearch */ /* @var $dataProvider yii\data\ActiveDataProvider */ $this->title = Yii::t('backend', 'Users'); $this->params['breadcrumbs'][] = $this->title; ?> <div class="user-index"> <p> <?php echo Html::a(Yii::t('backend', 'Create user'), ['create'], ['class' => 'btn btn-success']); ?> <?php echo Html::a(Yii::t('backend', 'Roles'), ['/rbac/access/role'], ['class' => 'btn btn-success']); ?> <?php echo Html::a(Yii::t('backend', 'Permissions'), ['/rbac/access/permission'], ['class' => 'btn btn-success']); ?> </p> <?php echo GridView::widget(['dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'columns' => ['id', 'username', 'email:email', ['attribute' => 'status', 'value' => function ($model) { return User::statuses($model->status); }, 'filter' => User::statuses()], 'ip', ['class' => 'yii\\grid\\ActionColumn', 'template' => '{update} {delete}']]]); ?> </div>