Yii Framework Forum: Cgridview With Multiple Models - Yii Framework Forum

Jump to content

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

Cgridview With Multiple Models Rate Topic: -----

#1 User is offline   Quentinb 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 46
  • Joined: 16-October 13

Posted 08 April 2014 - 02:13 AM

Hi All.

I have the following 2 models with a 1 to many relationship. One Organisation can have multiple connections:

CPConnection has a column organisation_id which holds the primary key value of the Organisation id column.


Model CpOrganisation:
public function relations()
{
	return array('connection' => array(self::BELONGS_TO, 'cp_connection', 'id'),
	);
}



Model CpConnection:
public function relations()
{
	return array('organisation' => array(self::HAS_ONE, 'cp_organisation', 'organisation_id'),
	);
}




My view file:
<?php $this->widget('zii.widgets.grid.CGridView', array(
	'id'=>'cp-connection-grid',
	'dataProvider'=>$model->search(),
	'filter'=>$model,
		
	'columns'=>array('organisation_id','connection_type_id','server_name',
		
			array('name'=>'Organisation',
'value'=>'$data->organisation->organisation_name',
						'type'=>'raw'),


	),
)); ?>



I keep getting: htmlspecialchars() expects parameter 1 to be string, array given

Any idea what I am doing wrong?
Do I have to set up a relationship on database level?
0

#2 User is offline   Quentinb 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 46
  • Joined: 16-October 13

Posted 08 April 2014 - 02:28 AM

Never mind, got it working. I created a relationship on database level and used Gii to set the relationship code on the model and all is working fine now.

Only other problem is that there is no filter option on the referenced column. How can I fix that? As per pic below.



Attached File  Capture.PNG (8.27K)
Number of downloads: 8
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