Yii Framework Forum: Column For Each Item Of Array In Cgridview - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Column For Each Item Of Array In Cgridview Rate Topic: -----

#1 User is offline   olsam 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 7
  • Joined: 27-December 12

Posted 27 December 2012 - 04:51 AM

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.
0

#2 User is offline   mbi 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 604
  • Joined: 08-May 09

Posted 27 December 2012 - 07:07 AM

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
0

#3 User is offline   olsam 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 7
  • Joined: 27-December 12

Posted 27 December 2012 - 09:12 AM

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

#4 User is offline   olsam 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 7
  • Joined: 27-December 12

Posted 28 December 2012 - 04:43 AM

No one can help me??
0

#5 User is offline   yugene 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 513
  • Joined: 08-August 09

Posted 28 December 2012 - 04:53 AM

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.
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users