Forign Key Dispaly Name Instead Of Id

hi

i make crud page that shows the id of foreign key

i want to view the name of foreign key instead of id.

I think you want something like this:


echo $model->relation->name;

See docs.

thanks for your replay it work :)

i just add

• in _view.php add the following :

<?php echo CHtml::encode($data->getAttributeLabel(‘AdsCompanys’)); ?>:</b>

&lt;?php echo CHtml::encode(&#036;data-&gt;adsCompanys-&gt;AdsCoName); ?&gt;

where getAttributeLabel(‘AdsCompanys’) is the name of table that you want to retrieve the data from.

the $data->relation_name->field you want to retrieve data from it.

• in View.php add the following instead of ‘AdsComapny_Id’:

array(

                'name' =&gt; 'AdsCompanys_Id',


                'value' =&gt; &#036;model-&gt;adsCompanys-&gt;AdsCoName),

where AdsCompany_id is the foreign key

and adsCoName is the field from related table that retrieve the data from.