Get Hasmany Relational Data To Display

hi I need to get data to display using relationship.I have has many relationship

following code will give error

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

help me.thanx in advance.

can you paste error here and describe your issue in detail.


If the relation of first model (resulting $data) has many userContactDetails then you can use

<?php echo CHtml::encode($data->userContactDetails[0]->phone_no_1); ?>

or if you want to display all information you can use


foreach ($data->userContactDetails as $item)

echo CHtml::encode($item->phone_no_1); 


But for complete answer please Post more details for your model and what you want to do.