Controller Variable In Gridview Cssclassexpression

So I declare a variable $time and pass it to the view. In the GridView columns array I am highlighting specific fields by date in cssClassExpression.

// View code snippet inside GridView widget




'cssClassExpression' => '($data->end_date <= $time) ? "highlight" : ""'



Not sure why $time is showing undefined since I pass it through render as ‘time’ => date(…),

Anyone able to shed some light here on the issue or how I can move past this. Thanks in advance.

Hi, try




'cssClassExpression' => '($data->end_date <= "'. $time .'") ? "highlight" : ""'



The cssClassExpression only recognises $row, $data and $this so any other variable being passed to cssExpression has to be concatenated as shown in the code.

I solved it was the duh… moment of my day.




'cssClassExpression' => ('$data->end_date' <= $time) ? '"highlight"' : '""',



Edit: I did however try the above mentioned throws this Parse error.

Parse error: syntax error, unexpected ‘19’ (T_LNUMBER) in C:\var\www\libphp\yii\framework\base\CComponent.php(612) : eval()'d code on line 1

I noticed the error. It appears you read my post while I was correcting it.