Trying To Get Property Of Non-Object In Cgridview

Hello,

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


<?php 

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

	'id'=>'teams-grid',

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

	'filter'=>Teams::model(),

	'columns'=>array(

	array(

		'class'=>'CCheckBoxColumn',

		'id'=>'rows_to_insert',

		'selectableRows' => 2,

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

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

		),

		'title',

		'level',

		'club'

	),

));   ?>

Here is what I am using to get the data


public function getTeamsByLevelIdAndCompetitionId($levelId, $competitionId) 

	{

		//console.log($competitionId);

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

      		 (SELECT COUNT(*) 

        FROM tbl_competition_teams ct

        WHERE ct.team = t.id

        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'=>'id',

    		'sort'=>array(

       	    'attributes'=>array(

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

        ),

    ),

));

	}

Any thoughts or help would be much appreciated thanks

Hi,

In my coding below code is working fine







'dataProvider'=>$model->search(),

[size=2]'filter'=>$model,[/size]



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





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

 'filter'=>$model,



and follow this link

http://www.yiiframework.com/forum/index.php/topic/14020-cgridview-with-carraydataprovider-sorting/

Try this cheers :)

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


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

Thanks!