I entered the users canViewsSite rule, I need if the user does not have such permission, then the fields would not be displayed. Tried to do so in the submission:

 $gridColums=[ [ 'attribute'=>'key_feild', 'value' => function($model){ return $model->canViewsKeyFeild($model); } ], [ 'attribute'=>'value', 'value' => function($model){ return $model->canViewsValue($model); }, ], ['class' => 'yii\grid\ActionColumn'], ]; 

Here in the model:

 public function canViewsKeyFeild($model){ if($model->key_feild=='site'){ if(Yii::$app->user->can('canViewsSite')){ return $model->key_feild; }else{ return false; } }else{ return $model->key_feild; } } 

But then an error occurs, the field is there, it is just not filled, and when editing in general, you can go in and see everything. Is it possible to somehow hide the fields in case the user does not have a canViewsSite rule and the value

 keyfeild == 'site' 

?

    1 answer 1

    For this there is a parameter visible

     $gridColumns = [ [ 'attribute' => 'key_feild', 'visible' => Yii::$app->user->can('canViewsSite'), ], [ 'attribute' => 'value', 'visible' => Yii::$app->user->can('canViewsSite'), ], ['class' => 'yii\grid\ActionColumn'], ];