I have two related models
class EmailTemplate extends CActiveRecord
{
public function relations()
{
return array(
'emailTemplateContents' => array(self::HAS_MANY, 'EmailTemplateContent', 'email_template_id'),
);
}
}
email_template
{id, name}
and
email_template_content
{id, email_template_id, locale, subject, body}
class EmailTemplateContent extends CActiveRecord
{
public function relations()
{
return array(
'emailTemplate' => array(self::BELONGS_TO, 'EmailTemplate', 'email_template_id'),
);
}
}
in admin.php for EmailTemplate I have this CGridView
<?php $this->widget('zii.widgets.grid.CGridView', array(
'id'=>'email-template-grid',
'dataProvider'=>$model->search($EmailTemplateContentEn, $EmailTemplateContentNl),
'filter'=>$model,
'columns'=>array(
'id',
'name',
array(
'header'=>'Subject en',
'name'=>'emailTemplateContents[en][subject]',
'value'=>'$data->emailTemplateContents[0]->subject'
),
array(
'header'=>'Body en',
'name'=>'emailTemplateContents[en][body]',
'value'=>'$data->emailTemplateContents[0]->body'
),
array(
'header'=>'Subject nl',
'name'=>'emailTemplateContents[nl][subject]',
'value'=>'$data->emailTemplateContents[1]->subject'
),
array(
'header'=>'Body nl',
'name'=>'emailTemplateContents[nl][body]',
'value'=>'$data->emailTemplateContents[1]->body'
),
array(
'class'=>'CButtonColumn',
),
),
)); ?>
This is works but can someone tell me if there is easier way to do this. What if there were 10 not 2 locales.