public function init() { parent::init(); $this->assignmentTable = Assignment::tableName(); $this->roleTable = Role::tableName(); $this->permissionTable = Permission::tableName(); $this->relationTable = Relation::tableName(); }
/** * Lists all Relation models. * @return mixed */ public function actionIndex($role) { if (\Yii::$app->request->isPost) { $selectedPermissions = LuLu::getPostValue('Permission'); Relation::AddBatchItems($role, $selectedPermissions); return $this->redirect(['index', 'role' => $role]); } $allPermissions = Permission::getAllPermissionsGroupedByCategory(); $rolePermissions = Relation::find()->select(['permission', 'value'])->where(['role' => $role])->indexBy('permission')->all(); $categories = Permission::getCategoryItems(); $role = Role::findOne(['id' => $role]); return $this->render('index', ['rolePermissions' => $rolePermissions, 'allPermissions' => $allPermissions, 'categories' => $categories, 'role' => $role]); }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Permission::find()->andWhere(['category' => $params['category']]); $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; } $query->andFilterWhere(['form' => $this->form, 'sort_num' => $this->sort_num]); $query->andFilterWhere(['like', 'id', $this->id])->andFilterWhere(['like', 'category', $this->category])->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'description', $this->description])->andFilterWhere(['like', 'options', $this->options])->andFilterWhere(['like', 'default_value', $this->default_value])->andFilterWhere(['like', 'rule', $this->rule]); return $dataProvider; }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Permission::find(); $query->orderBy('id asc,sort_num desc'); $dataProvider = new ActiveDataProvider(['query' => $query]); $this->load($params); $this->category_id = LuLu::getGetValue('category'); $query->andWhere(['category_id' => $this->category_id]); if (!$this->validate()) { // uncomment the following line if you do not want to any records when validation fails // $query->where('0=1'); return $dataProvider; } $query->andFilterWhere(['category_id' => $this->category_id, 'form' => $this->form]); $query->andFilterWhere(['like', 'id', $this->id])->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'description', $this->description]); return $dataProvider; }
<?php use source\helpers\Html; use yii\grid\GridView; use source\LsYii; use source\modules\rbac\models\Permission; /* @var $this yii\web\View */ /* @var $model source\modules\rbac\models\Role */ $category = LsYii::getGetValue('category'); $this->title = "修改" . Permission::getCategoryItems($category); ?> <div class="permission-update"> <?php echo $this->render('_form', ['model' => $model]); ?> </div>
/** * Finds the Permission model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param string $id * @return Permission the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Permission::findOne(['id' => $id])) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
<?php $form = ActiveForm::begin(['id' => 'permission-form', 'options' => ['class' => 'form-horizontal']]); ?> <?php echo $form->field($model, 'id')->textInput(['maxlength' => true]); ?> <?php echo $form->field($model, 'name')->textInput(['maxlength' => true]); ?> <?php echo $form->field($model, 'form')->radioList(Permission::getFormItems()); ?> <?php echo $form->field($model, 'default_value')->textarea(['rows' => 6]); ?> <?php echo $form->field($model, 'rule')->dropDownList(Rule::getRules(), ['prompt' => '请选择']); ?> <?php echo $form->field($model, 'description')->textarea(['rows' => 6]); ?> <?php
<?php use yii\helpers\Html; use source\core\grid\GridView; use source\LuLu; use source\modules\rbac\models\Permission; /* @var $this yii\web\View */ /* @var $searchModel app\modules\rbac\models\search\PermissionSearch */ /* @var $dataProvider yii\data\ActiveDataProvider */ $categoryId = LuLu::getGetValue('category'); $this->title = '权限管理'; $this->params['breadcrumbs'][] = $this->title; $columns = [['attribute' => 'id', 'width' => '150px'], ['attribute' => 'name', 'width' => '250px'], ['attribute' => 'description', 'width' => 'auto'], ['attribute' => 'form', 'value' => function ($model) { return Permission::getFormItems($model->form); }], ['class' => 'source\\core\\grid\\SortColumn'], ['class' => 'source\\core\\grid\\ActionColumn']]; $this->toolbars([Html::a('新建权限', ['create', 'category' => $categoryId], ['class' => 'btn btn-xs btn-primary mod-site-save'])]); ?> <style> .ui-tabs .ui-tabs-panel{padding:0px;} </style> <div class="da-ex-tabs"> <ul> <!-- <li><a href="#tabs-<?php echo Permission::Category_Basic; ?> ">基本权限</a></li> --> <li><a href="#tabs-<?php echo Permission::Category_Controller; ?> ">控制器权限</a></li> <li><a href="#tabs-<?php