Trying To Get Property Of Non-Object In Cgridview


I am generating a CGridView based on data provided by a CArrayDataProvider, and I have an extra column called ‘inCompetition’ which returns a 1 or a 0 based on whether or not the team is in the competition. It populates the CGridView fine, but when I try to access the data object, I get the error "Trying to get property of non-object ". I am trying to have it so it pre checks the check box if “inCompetition = 1”. I thought that the dataProvider is accessible through the variable $data?

Here is my CGridView, with the troublesome line in bold


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


	'dataProvider'=>Teams::model()->getTeamsByLevelIdAndCompetitionId($model->level, $model->id),






		'selectableRows' => 2,

		//'checked' => '$data->inCompetition == 1'

		[b]'checked' => '$data->inCompetition == 1'[/b]






));   ?>

Here is what I am using to get the data

public function getTeamsByLevelIdAndCompetitionId($levelId, $competitionId) 



		$rawData = Yii::app()->db->createCommand('SELECT t.*, 

      		 (SELECT COUNT(*) 

        FROM tbl_competition_teams ct

        WHERE =

        AND ct.competition = '.$competitionId.') AS inCompetition

		FROM tbl_teams t 

		WHERE t.level = '.$levelId)->queryAll();


        $params = array(

        	'levelId' => $levelId,

        	'competitionId' => $competitionId



		return new CArrayDataProvider($rawData, array(




             'id', 'title', 'level', 'club', 'inCompetition',





Any thoughts or help would be much appreciated thanks


In my coding below code is working fine



i hope in your code …below code should work fine …

'dataProvider'=>$model->getTeamsByLevelIdAndCompetitionId($model->level, $model->id),


and follow this link

Try this cheers :)

Thanks for the reply chandran, it turns out it was something simple, the line should have read

'checked' => '$data["inCompetition"]'