Yii2 gridview单元格的颜色,多种条件

Yii2 gridview单元格的颜色,多种条件,yii2,Yii2,如何像这样改变细胞的颜色 if($data['type'] == 'London' or $data['type'] == 'Manchester' and $data['from_sale']){ return ['style' => 'background-color:#BCC6F0;']; } 如果行中的“type”值为伦敦或曼彻斯特,则更改行中“from_sell”单元格的颜色。只能在“from_sell”行的两个单元格中更改颜色使用con

如何像这样改变细胞的颜色

if($data['type'] == 'London' or $data['type'] == 'Manchester' and $data['from_sale']){
            return ['style' => 'background-color:#BCC6F0;'];
        }

如果行中的“type”值为伦敦或曼彻斯特,则更改行中“from_sell”单元格的颜色。只能在“from_sell”行的两个单元格中更改颜色

使用
contentOptions

[
    'attribute' => 'attribute_name',
    'contentOptions' => function ($model, $key, $index, $column) {
        return ['style' => 'background-color:' 
            . ($model->type == 'London' ? 'red' : 'blue')];
    },
],

使用
contentOptions

[
    'attribute' => 'attribute_name',
    'contentOptions' => function ($model, $key, $index, $column) {
        return ['style' => 'background-color:' 
            . ($model->type == 'London' ? 'red' : 'blue')];
    },
],

我添加了这个
'value'=>'total','contentOptions'=>函数($model,$key,$index,$column){return['style'=>'background color:'。($model->type=='London'?'red':'blue');},
总计列中的单元格始终为蓝色,这可能是因为您的
$model->type
不是
London
。匿名函数不需要所有属性,因此您可以将其简化为
函数($model){
'value'=>'total',contentOptions'=>函数($model){return['style'=>'background color:'。($model->type=='eu_dhl'?'red':'blue')];},
不要使用
class
,使用
style
和作为值
背景色:#color
我添加了这个
'value'=>'total',contentOptions'=>函数($model,$key,$index,$column){return['style'=>'background color:'。($model->type=='London'?'red':'blue');},
总计列中的单元格始终为蓝色,这可能是因为您的
$model->type
不是
London
。匿名函数不需要所有属性,因此您可以将其简化为
函数($model){
'value'=>'total',contentOptions'=>函数($model){return['style'=>'background color:'。($model->type=='eu_dhl'?'red':'blue')];},
不要使用
class
,使用
style
并作为值
背景色:#color