Hello, i’m having some trouble with FK and related data on yii.
Here is my table structure:
Users: Events: Events_ocurred:
id_user(PK) id_events(PK) id (PK)
username description id_events (FK)
id_user (FK)
date
id_events on Events and Events_ocurred are type VARCHAR(11) because on my system 0049 != 00049 (i need to to this way)
so, on EventsOcurred Model:
public function relations()
{
'username' => array (self::BELONGS_TO, 'Usuario', 'id_user'),
'description' => array (self::BELONGS_TO, 'Events', 'id_events'),
);
}
On EventsOcurred View:
<b><?php echo CHtml::encode($data->getAttributeLabel('Name of Event')); ?>:</b>
<?php echo CHtml::encode($data->description->description); ?>
<br />
<b><?php echo CHtml::encode($data->getAttributeLabel('User')); ?>:</b>
<?php echo CHtml::encode($data->username->username); ?>
<br />
If i change description -> description i got a blank field, if i put as i told, i got this:
htmlspecialchars() expects parameter 1 to be string, object given
username -> username returns fine the name of user…