Answer the question
In order to leave comments, you need to log in
How to hide fields from certain GridView users?
I have led the rule `canViewsSite`
in users, if the user does not have such permission, then the fields should not be displayed.
tried to do so in the view
$gridColums=[
[
'attribute'=>'key_feild',
'value' => function($model){
return $model->canViewsKeyFeild($model);
}
],
[
'attribute'=>'value',
'value' => function($model){
return $model->canViewsValue($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;
}
}
`canViewsSite`
and a valuekeyfeild == 'site'
Answer the question
In order to leave comments, you need to log in
If I understood the task correctly, then you have a table in which there is a field name (key_feild) and its value (value), respectively, for users who do not have the canViewsSite permission, you need to hide the data with key_field = 'site'
Then it is not clear why this should be done on the GridView level if you can simply select data according to the appropriate conditions from the database. For example like this:
MyModel::find()->where(['not' in, 'key_field', 'site']);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question