<div class="col-sm-12"> <?php $form = ActiveForm::begin(['options' => ['class' => 'form-horizontal'], 'fieldConfig' => ['template' => "{label}<div class=\"col-sm-5\">{input}</div>", 'labelOptions' => ['class' => 'col-lg-3 control-label']]]); ?> <?php echo $form->errorSummary($model); ?> <?php echo $form->field($model, 'task_name')->textInput(['maxlength' => 64]); ?> <?php echo $form->field($model, 'task_category_id')->dropDownList(\bmprbac\rbac\models\RbacTaskCategory::getCategories(), ['prompt' => '全部类型']); ?> <?php echo $form->field($model, 'description')->textarea(['maxlength' => 200]); ?> <div class="form-group"> <?php echo Html::submitButton($model->isNewRecord ? '创建' : '保存', ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']); ?> </div> <?php ActiveForm::end(); ?>
public function actionCategoryCreate() { $model = new models\RbacTaskCategory(); $model->scenario = 'create'; // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->redirect(['category-admin']); } // 验证失败:$errors 是一个包含错误信息的数组 //$errors = $model->errors; return $this->render('/rbac/authtask/category_form', ['model' => $model]); }
?> </div> <?php echo Html::submitButton('搜索', ['class' => 'btn btn-default', 'item_name' => 'submit-button']); ?> <?php ActiveForm::end(); ?> </div> </div> <div class="box"> <div class="box-body"> <?php echo GridView::widget(['dataProvider' => $dataProvider, 'tableOptions' => ['class' => 'table table-bordered table-hover'], 'layout' => "{items}<div class='col-sm-5'>{summary}</div><div class='col-sm-7'><div class='dataTables_paginate'>{pager}</div></div>", 'columns' => ['task_id', 'task_name', ['attribute' => 'task_category_id', 'value' => function ($model) { return isset(\bmprbac\rbac\models\RbacTaskCategory::getCategories()[$model->task_category_id]) ? \bmprbac\rbac\models\RbacTaskCategory::getCategories()[$model->task_category_id] : ''; }], 'description', ['header' => '操作', 'class' => 'yii\\grid\\ActionColumn', 'template' => '{assign} {related-role} {view} {update} {delete}', 'buttons' => ['assign' => function ($url, $model, $key) { $options = ['title' => Yii::t('yii', '分配权限'), 'aria-label' => Yii::t('yii', '分配权限'), 'data-pjax' => '0']; return Html::a('<span class="glyphicon glyphicon-check"></span>', $url, $options); }, 'related-role' => function ($url, $model, $key) { $options = ['title' => Yii::t('yii', '已分配的角色'), 'aria-label' => Yii::t('yii', '已分配的角色'), 'data-pjax' => '0', 'class' => 'relatedUserBtn', 'ref' => $url]; return Html::a('<span class="glyphicon glyphicon-user"></span>', $url, $options); }]]]]); ?> </div> </div> </div> <div class="col-sm-2"> <div class="box box-primary">
/** * 角色分配任务 * 根据任务分类来过滤和显示数据 * * @author lixupeng */ public function actionAssignTask($id) { $model = self::findModel($id); // 先获取授权分类 $task_categorys = models\RbacTaskCategory::getCategories(); $searchParams = Yii::$app->request->queryParams; $task_category = isset($searchParams['task_category']) ? $searchParams['task_category'] : null; //任务列表 $unassign = $taskItems = models\RbacAuthtask::getTasksByCategory($task_category); // 已授权的 $authorized = models\RbacRoleTask::getTaskAuthorized($id); // 从所有授权任务中过滤出已经授权的 if ($authorized) { foreach ($authorized as $k => $v) { unset($unassign[$v]); } } $authorized = array_intersect_key($taskItems, array_flip($authorized)); return $this->render('/rbac/role/assignTask', ['model' => $model, 'unassign' => $unassign, 'assigned' => $authorized, 'task_categorys' => $task_categorys, 'task_category' => $task_category]); }
use yii\widgets\DetailView; $this->title = '授权任务管理'; $this->params['breadcrumbs'][] = ['label' => '授权任务管理', 'url' => ['index']]; $this->params['breadcrumbs'][] = $model->task_id; ?> <div class="box box-info"> <div class="box-body"> <div class="col-sm-12"> <h3><?php echo Html::encode('查看任务#' . $model->task_id); ?> </h3> <?php echo DetailView::widget(['model' => $model, 'attributes' => ['task_id', 'task_name', ['attribute' => 'task_category_id', 'value' => isset(\bmprbac\rbac\models\RbacTaskCategory::getCategories()[$model->task_category_id]) ? \bmprbac\rbac\models\RbacTaskCategory::getCategories()[$model->task_category_id] : ''], ['attribute' => 'description', 'value' => Html::encode($model->description)]]]); ?> <p> <?php echo Html::a('分配权限', ['assign', 'id' => $model->task_id], ['class' => 'btn btn-primary']); ?> <?php echo Html::a('编辑', ['update', 'id' => $model->task_id], ['class' => 'btn btn-primary']); ?> <?php echo Html::a('删除', ['delete', 'id' => $model->task_id], ['class' => 'btn btn-danger', 'data' => ['confirm' => '你确定删除此角色吗?', 'method' => 'post']]); ?> </p> </div> </div>