View a related field in CGridView

Comparing #3 with #4

Revision #4 was created by rafaelt88 rafaelt88 on Jun 30, 2015, 9:09:23 PM.

View a related field in CGridView

Content

[...]
2) First, it is necessary to specify that the model will use the relationship defined above; Then, the comparison between the related field and a variable is defined; Finally, specify what will be the order for the field shown in CGriView.
~~~~
class TableB extends ActiveRecord {
...
public function search() {
$criteria = new CDbCriteria();
$criteria->with = array('tableA');
...
[...]
array(
'name' => 'tableA.name',
      'value' => '$data->tableA->name)',
 
'filter' => CHtml::textField('tableA_name', Yii::app()->request->getParam('tableA_name')),
),
...
),
...
));
[...]