Reputation: 319
I have this in my view
'columns' => [
['class' => 'yii\grid\SerialColumn'],
[
'attribute' => 'order_delivery_address_city',
'value' => 'address.order_delivery_address_city'
],
which shows field like '1' or '2' or '3'... How to change it to be like this
if (address.order_delivery_address_city == '1') {
'value' => 'New-York'
}
Upvotes: 2
Views: 3331
Reputation: 912
It will work fine. Try this way.
'columns' => [
['class' => 'yii\grid\SerialColumn'],
[
'attribute' => 'order_delivery_address_city',
'value' => function($model){
$city_name = City::find()->select(['city_name'])->where(['city_id' => $model->order_delivery_address_city])->one();
return $city_name ? $city_name->city_name:'None';
},
],
It will look into City table and will search single record for matching city_id as contained in order_delivery_address_city and return the corresponding city_name. If no matching record found then it will return None.
Upvotes: 1
Reputation: 399
Try this:
[
'attribute'=>'order_delivery_address_city',
'value'=>function($model){
return $model->order_delivery_address_city=='1' ? 'New-York':'Anything else';
}
],
Upvotes: 2
Reputation: 5456
Try:
'columns' => [
['class' => 'yii\grid\SerialColumn'],
[
'attribute' => 'order_delivery_address_city',
'value' => function($model){
if($model->address->order_delivery_address_city == '1'){
return 'New-York';
}
}
],
Upvotes: 2