コード例 #1
0
ファイル: RbacManager.php プロジェクト: merlinxie/lulublog
 public function init()
 {
     parent::init();
     // custom initialization code goes here
     $this->assignmentTable = Assignment::tableName();
     $this->roleTable = Role::tableName();
     $this->permissionTable = Permission::tableName();
     $this->relationTable = Relation::tableName();
 }
コード例 #2
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Permission::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $this->load($params);
     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, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at]);
     $query->andFilterWhere(['like', 'key', $this->key])->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'rule', $this->rule])->andFilterWhere(['like', 'data', $this->data])->andFilterWhere(['like', 'note', $this->note]);
     return $dataProvider;
 }
コード例 #3
0
 /**
  * Lists all Relation models.
  * @return mixed
  */
 public function actionIndex($role)
 {
     $rolePermissions = Relation::find()->select(['permission', 'value'])->where(['role' => $role])->indexBy('permission')->all();
     if (\Yii::$app->request->isPost) {
         var_dump(LuLu::getPostValue('Permission'));
         $selectedPermissions = LuLu::getPostValue('Permission');
         $keys = array_keys($selectedPermissions);
         Relation::deleteAll(['role' => $role]);
         foreach ($selectedPermissions as $key => $value) {
             $newRelation = new Relation();
             $newRelation->role = $role;
             $newRelation->permission = $key;
             $newRelation->value = is_string($value) ? $value : implode(',', $value);
             $newRelation->save();
         }
         return $this->redirect(['index', 'role' => $role]);
     }
     $allPermissions = Permission::findAll();
     return $this->render('index', ['rolePermissions' => $rolePermissions, 'allPermissions' => $allPermissions]);
 }
コード例 #4
0
ファイル: _form.php プロジェクト: merlinxie/lulublog
?>

    <?php 
echo $form->field($model, 'key')->textInput(['maxlength' => 64, 'readonly' => $model->isNewRecord ? false : true]);
?>

    <?php 
echo $form->field($model, 'category_id')->dropDownList($categories);
?>

    <?php 
echo $form->field($model, 'name')->textInput(['maxlength' => 64]);
?>

    <?php 
echo $form->field($model, 'form')->radioList(Permission::getForms());
?>

    <?php 
echo $form->field($model, 'options')->textarea(['rows' => 6]);
?>

    <?php 
echo $form->field($model, 'default_value')->textarea(['rows' => 6]);
?>
    
    <?php 
echo $form->field($model, 'note')->textarea(['rows' => 6]);
?>

    <div class="form-group">
コード例 #5
0
ファイル: index.php プロジェクト: merlinxie/lulublog
<?php

use yii\helpers\Html;
use yii\grid\GridView;
use source\LuLu;
use app\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_id');
$this->title = '权限管理';
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="permission-index">


    <p>
        <?php 
echo Html::a('新建权限', ['create', 'category_id' => $categoryId], ['class' => 'btn btn-success']);
?>
    </p>

    <?php 
echo GridView::widget(['dataProvider' => $dataProvider, 'columns' => [['class' => 'yii\\grid\\SerialColumn'], 'key', 'name', ['class' => 'yii\\grid\\DataColumn', 'attribute' => 'form', 'value' => function ($model) {
    return Permission::getForms($model->form);
}], ['class' => 'yii\\grid\\ActionColumn']]]);
?>

</div>
コード例 #6
0
 /**
  * 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(['key' => $id])) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }