I have a simple function that returns the name of a category. I tested it as shown below with an exit statement after the echo test.
public function getCategory($id = null)
{
$category=FaqCategories::model()->findByPk($id);
echo $category->category;
exit;
return $category;
}
It echos back the correct answer. I then took out the exit, and Yii errors out saying that I am "Trying to get property of non-object" and pointing to the echo line which previously just worked perfectly. No matter where I try to get the $category->category result, unless I exit Yii immediately it errors. What am I doing wrong?
I am guessing you are calling getCategory() more than once in the request, and it works the first time, but one of the latter times, you are probably passing an invalid ID to it