list for related records in detailed view

I have two tables

Customers


idCustomer (PK)

name

surname

Contacts


idContacts

CustomerID (FK)

detail

So that One Customer has many Contacts. Provided that:

  1. I defined the relation in mysql

  2. 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?

No one can help me? please…

something like


$model->contacts

I suppose.

For details, read this.

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

Thanks for your help… Another question: Where do I have to put _contacts.php?