Yii Framework Forum: Joined tables with CGridView - Yii Framework Forum

Jump to content

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

Joined tables with CGridView Rate Topic: -----

#1 User is offline   rikardo 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 50
  • Joined: 16-December 09
  • Location:Sweden

Posted 07 June 2010 - 02:19 AM

I have two tables: 'Subscriptions' and 'Customers', it's a one to one relationship.
With the CGridView I want be able to search the 'customer.Customernumber' field.
For the moment it only shows the value of that field.

(The widget shows the 'Subscriptions' table with 'Customers' joined)
<?php $this->widget('zii.widgets.grid.CGridView', array(
	'id'=>'subscription-grid',
	'dataProvider'=>$model->search(),
	'filter'=>$model,
	'columns'=>array(
		'customer.Customernumber',
		'ActiveStatus',
		array(
			'class'=>'CButtonColumn',
		),
	),
)); ?>


Is this supported by the widget functionality?
0

#2 User is offline   rikardo 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 50
  • Joined: 16-December 09
  • Location:Sweden

Posted 07 June 2010 - 06:29 AM

Read in another topic on the same startpage for this forum, it did give me some information but not all, so the existence of this thread could still be useful.

Solved it like this:

  • Added a new member to the Subscriptions table called '$aux_customerNumber'.
  • Added '$aux_customerNumber' to the safe attribute list (THIS WAS THE MISSING PART FROM THE OTHER THREAD)
  • Added this to the search method in the model:
    $criteria->addSearchCondition('customer.CustomerNumber', $this -> aux_customerNumber, true);

  • This is how the column information is present in the view file:
    		array(
    			'header' => 'Customer number',
    			'name' => 'aux_customerNumber',
    			'filter' => CHtml::activeTextField($model, 'aux_customerNumber'),
    			'value' => '$data -> customer -> CustomerNumber',
    		),

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