My CGridView code is:
$this->widget('zii.widgets.grid.CGridView', array( 'dataProvider'=>$dataProvider, 'columns'=>array( array( 'name'=>'year', 'cssClassExpression'=>'($data->year >= 2000)?\'current\':\'old\'', ), ), ));
I attempted to use three different data providers, all containing the same structure and data, like so:
// attempt 1 $dataProvider = new CActiveDataProvider('Vehicle'); // attempt 2 $dataProvider = new CSqlDataProvider('SELECT id, year FROM vehicle'); // attempt 3 $dataProvider = new CArrayDataProvider(array(array('id'=>1,'year'=>'1998'),array('id'=>2,'year'=>'1999')));
When I used the CActiveDataProvider the view rendered successfully and the expected class had been set on the table cell. However, when I tried with either the CArrayDataProvider or the CSqlDataProvider I get the error: "Error 500 Trying to get property of non-object".
Is this a bug, or is the $data object not supposed to be available when using CDataProviders other than the CActiveDataProvider? If this is the intended functionality, is there any way around this? I definitely need to be able to access the values from the current "row" for dynamic manipulation/styling of some data. Thanks!
Edit and Clarification: This applies to Yii 1.1.4.