I’m very new to Yii. I’m using the current stable version of Yii.
I’ve read a lot on the use of relations and pivot tables, but I still cannot get this to work. I think I’m missing something, but I cannot find what it is.
I have a table named Biography with an ID and some columns with data about a person. I have a table named Media which includes an ID, fileName and fileLocation (URL). I have a pivot table named BioMedia with an ID, profileId (the Biography ID) and mediaId (the media table ID). I have generated models for all 3 tables.
In the Biography model, I have:
public function relations()
{
return array(
'media'=>array(self::MANY_MANY, 'Media',
'BioMedia(profileId, mediaId)'),
);
}
In the Media table, I have:
public function relations()
{
return array(
'Biography'=>array(self::MANY_MANY, 'Biography',
'BioMedia(mediaId, profileId)'),
);
}
In my view, I have:
<span style="float:left;">
<?php $images = Biography::model()->with('media')->findAll();
if ($images == !NULL) {
foreach ($images as $image):
?>
<img src="<?php echo Yii::app()->request->baseUrl; echo $image; ?>" alt="biography images" />
<?php endforeach;
} ?>
</span>
I get the error "Object of class Biography could not be converted to string" when I run this. If I take out the foreach, I get just get Array.
What am I doing incorrectly?
Thanks for any help you can provide.