Hi Yii fans,
I’m building a flight application. In my flight model, I’ve defined two relations:
return array(
'pilote'=>array(self::BELONGS_TO, 'Annuaire','cdtbord'),
'coPilote'=>array(self::BELONGS_TO, 'Annuaire','copilote'),
);
In my flight model, cdtbord field is required but copilote not.
For a solo flight (no copilot), a new created row set copilote field to 0. That value has no related record in model Annuaire.
In my gridview for displaying the flights:
array(
'header'=>'Co pilote',
'type'=>'raw',
'value'=>'$data->coPilote->nom_prenom',
'filter'=>CHtml::activeDropDownList($model, 'copilote', CHtml::listData(Vol::model()->findAll(),'copilote','coPilote.nom_prenom'),array('prompt'=>'','class'=>'span3')),
),
drop me an error saying "Trying to get property of non-object " while fetching the row with copilote field set to 0 … Not surprising in fact.
I’ve tried something like:
'value'=>'if($data->copilote!="0")$data->coPilote->nom_prenom',
no errors, but filled fields aren’t displayed at all …
Some help will be very appreciate.
Regards from France