Hi all,
I’m a newbie with YII and I can’t seem to figure out how to display a related field in a textArea.
In my Managers model I have:
public function relations()
{
// NOTE: you may need to adjust the relation name and the related
// class name for the relations automatically generated below.
return array(
'jobs' => array(self::HAS_MANY, 'Job', 'manager_ref'),
);
}
In my Jobs model I have:
public function relations()
{
// NOTE: you may need to adjust the relation name and the related
// class name for the relations automatically generated below.
return array(
'managerRef' => array(self::HAS_ONE, 'Managers', 'manager_ref'),
);
}
In my job/view update form:
<div class="row">
<?php echo $form->labelEx($model,'manager_ref'); ?>
<?php echo $form->dropDownList($model,'manager_ref', CHtml::listData(Managers::model()->findAll(), 'manager_ref', 'full_name')); ?>
<?php echo $form->error($model,'manager_ref'); ?>
</div>
<div class="row">
<?php echo "Manager Address"; ?>
<?php echo $form->textArea($model, $model->managerRef->address, array('rows'=>5, 'cols'=>75)); ?>
<?php echo $form->error($model,'manager_ref'); ?>
</div>
Gives “trying to get property of non-object”
<?php echo $form->textArea($model, 'managerRef->address', array('rows'=>5, 'cols'=>75)); ?>
Gives “Property "Job.managerRef->address" is not defined.”
The drop down list works fine displaying the correct Manager for each Job.
I’m probably missing something really simple but, is what I’m trying to do possible?
Any help would be greatly appreciated.
Cheers,
Mike T