S
S
Stanislav2016-08-07 14:16:29
Yii
Stanislav, 2016-08-07 14:16:29

How can I get the cell object in the GridView to use RBAC validation?

Let's have this code:

echo GridView::widget([
    'dataProvider' => $dataProvider,
    'columns'=>[
    	['class'=>'yii\grid\SerialColumn'],
    [
      'label'=>'User',
      'attribute'=>'users.userName'
    ],
    'title',
    'text',
    'date',
    'time',
    [
      'class' => 'yii\grid\ActionColumn',
      'header'=>'Actions',
      'template'=>'{view} {update} {delete} ',
      'buttons'=>[
        'view'=>function($url)
        {
          return Html::a('Открыть',$url);
        },
        'delete'=>function($url)
        {
          return Yii::$app->user->can('deletePost') ? Html::a('Удалить',$url) :  null ;
        }
      ]
    ],
    ]
]);

How can I get the current record?
I need to perform a similar check for the right to change the entry by the user who created it:
Yii::$app->user->can('updatePost',['posts'=>$post]) ? Html::a('Update',$url) :  null ;

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Andrew, 2016-08-07
@Stasgar

'buttons' => [
    'view'=>function($url) {
         return Html::a('Открыть', $url);
    },
    'update' => function($url, $model) {
         return Yii::$app->user->can('updatePost', ['posts' => $model->id]) ? Html::a('Изменить', $url) :  null ;
    }
]

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question