Render Foreign Key Dropdown as Text in Detail View

Hello all,

I can’t seem to figure out how to render the ‘Type’ value from a dropdown list that has a FK in the details view (_view). It returns the ID # - I want it to return the ‘Type’ value instead.

Here is the code in _view:


<b><?php echo CHtml::encode($data->getAttributeLabel('sporttype_id')); ?>:</b>

<?php echo CHtml::encode($data->sporttype_id); ?>

<br />

Snapshot:

1483

yii1.jpg

Thank you,

aki

If you have your relations well written, then it is just a matter of calling the relation and the value

Assuming model SportType [id,name]




// on model Team

public function relations(){

      return array(

          'sport'=>array(self::BELONGS_TO, 'SportType', 'sporttype_id'),

);

}


// then on your view

<b><?php echo CHtml::encode($data->getAttributeLabel('sporttype_id')); ?>:</b>

<?php echo CHtml::encode($data->sport->name); ?>

<br />



Excellent- thanks much Antonio! Coming from Cake.