I Have This Error Trying To Get Property Of Non-Object

Hi everybody,

I have two tables: "demande" and "statut". the primary key of "statut" migrates in "demande". I generated the models, controllers and views with gii. I inserted data in theses tables.

But when I want to view the recorded information, it sends me an error "[color="#FF0000"]Trying to get property of non-object[/color]".

Here one view called "view"

<?php SysImmo::getNavigation();?><?php

/* @var $this DemandeController */

/* @var $model Demande */







<?php $this->widget(‘zii.widgets.CDetailView’, array(






  [color=&quot;#FF0000&quot;]  array(






)); ?>

Help me please, what is the problem

Excuse my English, I’m French

You assume that StatutDemande::model()->findByPk($model->statut) always returns an object which apparently is not true, that is there is no related record.

Also, you should just use relations, not fetch records manually by providing the FK value. Read the guide about relations.

Hi nineinchnick

Thank you for taking the time to respond. I find the reason why I had this error. In fact, some record of the table "demande" in the database did not receive the foreign key from "statut". (I had allowed zero values ​​for testing and I forgot to put the clause not null). thank you for the tutorial, it is very rich. it will help me for the future.