Example #1
0
 private function getRoleModel()
 {
     $user = Yii::$app->user;
     if ($user->isGuest) {
         $roleModel = RbacRole::findOne(['name' => 'guest']);
     } else {
         $roleModel = Yii::$app->user->identity->getRoleModel();
     }
     return $roleModel;
 }
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = RbacRole::find();
     // add conditions that should always apply here
     $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;
     }
     // grid filtering conditions
     $query->andFilterWhere(['id' => $this->id]);
     $query->andFilterWhere(['like', 'name', $this->name]);
     return $dataProvider;
 }
Example #3
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getRole()
 {
     return $this->hasOne(RbacRole::className(), ['id' => 'role_id']);
 }
 /**
  * Finds the RbacRole model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  *
  * @param int $id
  *
  * @return RbacRole the loaded model
  *
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = RbacRole::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
Example #5
0
use yii\helpers\ArrayHelper;
/* @var $this yii\web\View */
/* @var $searchModel juliardi\simplerbac\models\RbacAccessRulesSearch */
/* @var $dataProvider yii\data\ActiveDataProvider */
$this->title = 'Rbac Access Rules';
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="rbac-access-rules-index">

    <h1><?php 
echo Html::encode($this->title);
?>
</h1>
    <?php 
// echo $this->render('_search', ['model' => $searchModel]);
?>

    <p>
        <?php 
echo Html::a('Create Rbac Access Rules', ['create'], ['class' => 'btn btn-success']);
?>
    </p>
    <?php 
echo GridView::widget(['dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'columns' => [['class' => 'yii\\grid\\SerialColumn'], ['label' => 'Role', 'attribute' => 'role_id', 'filter' => ArrayHelper::map(RbacRole::find()->all(), 'id', 'name'), 'value' => function ($data) {
    return $data->role->name;
}], ['label' => 'Route', 'attribute' => 'route_id', 'filter' => ArrayHelper::map(RbacRoute::find()->all(), 'id', 'name'), 'value' => function ($data) {
    return $data->route->name;
}], ['class' => 'yii\\grid\\ActionColumn']]]);
?>
</div>