Answer the question
In order to leave comments, you need to log in
How to make conditions in Gridview to replace the output data?
I want to display data on stores in a Gridview table. But the store is stored as a number and not as a string value, I did not find how you can change the value by condition, for example, switch .
[
'attribute' => 'id_shop',
'value'=>switch ($model->id_shop) {
case 2;
$model->id_shop= 'Московский';
break;
case 6;
$model->id_shop= 'Пушкина';
break;
case 9;
$model->id_shop= 'Сибирский';
break;
case 12;
$model->id_shop= 'Четаева';
break;
case 16;
$model->id_shop= 'Маркса';
break;
},
],
Answer the question
In order to leave comments, you need to log in
[
'attribute' => 'id_shop',
'value'=> function ($model) {
switch ($model->id_shop) {
case 2;
return 'Московский';
case 6;
return 'Пушкина';
case 9;
return 'Сибирский';
case 12;
return 'Четаева';
case 16;
return 'Маркса';
}
return null;
}
],
[
'attribute' => 'id_shop',
'value'=> function (MyModel $model) {
return ArrayHelper::getValue(MyModel::getShopList(), $model->shop_id);
}
],
MyModel extends Model {
public static function getShopList(){
return [
2 => 'Московский',
6 => 'Пушкина',
9 => 'Сибирский',
12 => 'Четаева',
16 => 'Маркса',
];
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question