Column For Each Item Of Array In Cgridview

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.

I would display email_template_content in view.php of emailTemplate

If you want to show mail bodies of all 10 languages, I expect it will mess up your gridview

10 languages is just an example. Thera are just 2 of them. I thinking there should be easier way to do this.

No one can help me??

You may always fill your ‘columns’ array in a loop :)

One more variant - write class or method to fill it.

Or write custom implementation, using your own class for columns render - you’ll need to extend CGridColumn class - take a look at /framework/zii/grid classes code for examples and better understanding what to exactly to do to implement your idea.