crisdev77
(Crisdev77)
1
I have two tables
Customers
idCustomer (PK)
name
surname
Contacts
idContacts
CustomerID (FK)
detail
So that One Customer has many Contacts. Provided that:
-
I defined the relation in mysql
-
I created via Gii the models for the two table and the CRUD generator for Customer model
I need in detail view (path/to/application/index.php?r=Customers/view&id=1) to see a list of related record in contacts table. How can i Do it?
crisdev77
(Crisdev77)
2
No one can help me? please…
tri
(tri - Tommy Riboe)
4
Quick fix:
Add this to the detail view you already have (view.php)
...
'attributes'=>array(
...
array(
'label'=>'Contacts:',
'type'=>'raw',
'value'=>$this->renderPartial('_contacts', array('model'=>$model), true),
),
),
_contacts.php
<?php
foreach ($model->contacts as $contact)
{
$this->widget('zii.widgets.CDetailView', array(
'data'=>$contact,
'attributes'=>array(
'idContacts',
'detail',
),
));
}
/Tommy
crisdev77
(Crisdev77)
5
Thanks for your help… Another question: Where do I have to put _contacts.php?