Php Notice : Trying To Get Property Of Non-Object

<?php

$state = State::model();

	&#036;countries = Country::model()-&gt;findAll();


	&#036;htmlOptions = array();


	foreach(&#036;countries AS &#036;country ) {


		&#036;states = &#036;state-&gt;findByAttributes(array('country_id' =&gt; &#036;country-&gt;id));


		// &#036;list = CHtml::listData(&#036;states, 'id', 'name');


		&#036;options = CHtml::listOptions('', &#036;states, &#036;htmlOptions);


		// print_r(&#036;options); exit;


	}


	echo CHtml::dropDownList('name', null, &#036;options);

?>

ERROR :

PHP notice : Trying to get property of non-object

states.php

there is a dropdownlist (states)in a form, when we click the state name,it has been show with the country details that are present in the country table.

thanks

PHP should report the exact line number where it happens. If not, try to define YII_DEBUG set to true in your index.php or vhost configuration.

Such errors happen oftern when you try to read a property from an object retrieved by some method but that method returned null.

If you had defined the states as a relation in the Countries model you don’t have use findByAttributes to get them, just read them as an attribute of $country.

thanx its works fine.,