Cannot Get Cgridview To Work With Cactivedataprovider

Inside the controller:


$locationsProvider = new CActiveDataProvider('CustomerLocations',

	array(

		'criteria'=>array(

			'select'=>array('t.name AS lname', 'DATEDIFF(t.date_expires, CURDATE()) AS gracePeriod',

				'idCountry.name AS coname', 'idState.name AS sname', 'idCity.name AS cname'),

			'condition'=>'active=1 AND DATEDIFF(t.date_expires, CURDATE()) < :period',

			'params'=>array(':period'=>Yii::app()->params['locationsGracePeriod']),

			'with'=>array(

				'idCountry'=>array('select'=>''),

				'idState'=>array('select'=>''),

				'idCity'=>array('select'=>''),

			),

		),

		'sort'=>array(

			'attributes'=>array(

				'lid'=>array('asc'=>'t.id', 'desc'=>'t.id DESC', 'label'=>'Id'),

				'lname'=>array('asc'=>'lname', 'desc'=>'lname DESC', 'label'=>'Name'),

				'gracePeriod'=>array('asc'=>'gracePeriod', 'desc'=>'gracePeriod DESC', 'label'=>'Ends in .. days'),

				'coname'=>array('asc'=>'coname', 'desc'=>'coname DESC', 'label'=>'Country'),

				'sname'=>array('asc'=>'sname', 'desc'=>'sname DESC', 'label'=>'State'),

				'cname'=>array('asc'=>'cname', 'desc'=>'cname DESC', 'label'=>'City'),

			),

			'defaultOrder'=>array('gracePeriod'=>CSort::SORT_ASC)

		),

		'pagination'=>array('pageSize'=>20),

	)

);



Inside the view:


$this->widget('zii.widgets.grid.CGridView', array(

	'dataProvider'=>$locationsProvider,

	'columns'=>array(

		'lname',

		'gracePeriod',

		'coname',

		'sname',

		'cname'

	)

));

The gridview shows no rows, although the headers and sort functionality seems to be there. Obviously, I’m missing something here. Can you help?

Dear Friend

Did you make all these derived properties as virtual properties.




public $lname;

public $gracePeriod;

public $coname;

public $sname;

public $cname;


//make them safe on search...

public function rules()

	{

		

		return array(

			array('name', 'required'),

		...........................................................

			array('id, lname,gracePeriod,coname,sname,cname', 'safe', 'on'=>'search'),

		);

	}




If you have already done that, I am not having any clue.

Regards.

Yes, this works, thank you very much. CGridView with the data providers has given me headaches now and then.

All the best. :)