In Yii form Edit action, I get a following Error, “Trying to get property of Non-Object”. I don’t know how to solve this. Anyone?
In Yii form Edit action, I get a following Error, “Trying to get property of Non-Object”. I don’t know how to solve this. Anyone?
Dump your variables/models to see, what their values are. Put the following at the beginning of your view:
<?php
CVarDumper::dump($var);
die;
?>
You have to change $var against your $model or other $variable.
If there are not the values you expected go backwards with the debugging into your controller:
Do you realy send the needed $model/$variable from the controller to the view: Look at $this->render…
Then look at the point in the controler where you build the $model/$variable - what’s going on there?
Hope this helps. You have to experiment with CVarDumper a lot … and I am shure you’ll like and need it in furture very often.
paste the whole stack error line number and relevant code
Somewhere along the way, it failed to load an object into the variable you’re trying to access. You should add error checking on whether the model is actually found, passed to the view, passed to any form partial you’re using, etc. Without seeing the actual code, trying to help is really just a stab in the dark.
Using the CVarDumper just before where you’re getting the error can be very helpful. Using CHtml::value() is a great way to provide a graceful failure when trying to display model attributes.