I’ve been playing around with a simple database with two tables: User and Profile. Profile has a foreign key, which points to the User table. Now what I wanted to achieve is a profile view, where I can display both data from the User and Profile tables.
I’ve noticed that there is this nice widget CDetailView, but the problem is with the attributes. E.g.
displays the Profile model attributes fine (according to the attributeLabels() method). Now if I want to access the User table through the ActiveRecord relation, the attribute labels aren’t as they should be.
displays User Username instead of the attribute label configured in the User model.
I would appreciate any help with this. Or maybe I’m trying to do too much with that widget? Is there a better way? A simple HTML table with php displaying the values from models works, but I wanted something more elegant and flexible.
$this->widget('zii.widgets.CDetailView', array(
'data'=>$profile,
'attributes'=>array(
'fname',
'sname',
array(
'label'=>'username',
'type'=>'raw', // here's a parameter that disable HTML escaping by Yii
'value'=>'$data->user->username', // here You can simple use CHtml::link() method
),
),
));