Trying to get property of non-object in view file

Hi all,

Here is the code that i used in controller

$model=new RsFile;

		$data	=	$model->findAllByPk($_GET['resid']);






when I print the $data variable in view(add-questions) it shows all records based on resid from query string means it shows

[_attributes:CActiveRecord:private] => Array ( [id] => 40 [name] => [title] => New Test Game [keywords] => asdasd [is_public] => 1 [description] => asdasd [user_id] => 0 [user_ip] => [status] => Pending [resource_type_id] => 5 [created] => 2012-01-05 09:39:33 [updated] => 0000-00-00 00:00:00  => 0000-00-00 00:00:00 ) [_related:CActiveRecord:private] => Array ( ) [_c:CActiveRecord:private] => [_pk:CActiveRecord:private] => 40 [_alias:CActiveRecord:private] => t [_errors:CModel:private] => Array ( ) [_validators:CModel:private] => [_scenario:CModel:private] => update [_e:CComponent:private] => [_m:CComponent:private] => ) ) 

but when I call this line


it gives me error of "Trying to get property of non-object"

Plz help if any body have an idea.

Topic moved.

findAllByPk() returns an array of objects:

foreach ($data as $obj)


    echo $obj->id;


Maybe you wanted findByPk() method?

here is an other example

I used this code in Controller

$condition	=	"id = :res";

$params	=	array(':res'=>$Questionid);	

$QuestionInfo	=	Question::model()->find($condition,$params);

Now when I write this

echo $QuestionInfo->question_type_id;exit;

it prints the value perfectly

but when I use this to assign it to new variable like this


it gives error Trying to get property of non-object

I am a newbie and working on it. This same example is working fine in view file but in controller it gets error.

Anyone having idea about it will be highly appriciated

maybe it will help or not…



print_r($data->attributes); //to check $data object has id attribute

check $QuestionInfo has ‘id’ property or $QuestionInfo has any value.


line may return NULL if no values found matching the given condition in $condition.