Hi,
i have a problem in displaying relational data. The situation is like this: My models are contacts and locations.
Contacts.php:
public function relations()
{
return array(
'locations' => array(self::HAS_MANY, 'Locations', 'contact_id'),
'persons' => array(self::HAS_MANY, 'Persons', 'contact_id'),
);
}
view.php:
<h1>View Contacts #<?php echo $model->id; ?></h1>
<?php $this->widget('zii.widgets.CDetailView', array(
'data'=>$model,
'attributes'=>array(
'id',
'name',
),
));
?><h2>Locations</h2>
<?php
$locations = Locations::model()->find("contact_id",$model->id);
$i=-1;
while($i++<count($locations)) {
$this->widget('zii.widgets.CDetailView', array(
'data'=>$locations,
'attributes'=>array(
'id',
'street',
'nr',
'zip',
'city',
'country',
),
));
}
?>
Somehow only 1 location is displayed even if there are two in the db. What am i doing wrong!?
Thanks for your help…
Flo