Mysql 带有关系表的CGridView

Mysql 带有关系表的CGridView,mysql,yii,yii-cactiverecord,Mysql,Yii,Yii Cactiverecord,我有两个关系表:location和location\u类型 位置 - location_id - location_name - location_type_id 位置类型 - location_type_id - location_type 我用CGridView小部件创建了一个视图,一切正常,甚至文件管理器字段也正常工作,除了location\u type列中只显示location\u type\u id 视图中的CGridView小部件: $this->widge

我有两个关系表:location和location\u类型

位置

  - location_id
  - location_name
  - location_type_id
位置类型

 - location_type_id
 - location_type
我用CGridView小部件创建了一个视图,一切正常,甚至文件管理器字段也正常工作,除了location\u type列中只显示location\u type\u id

视图中的CGridView小部件:

$this->widget('zii.widgets.grid.CGridView', array(
'dataProvider' => $model->search(),
'filter' => $model,
'columns' => array(
    array('name' => 'location', 'header' => 'Location'),
    array(           
        'name' => 'location_type_id', 
        'header' => 'Location Type'
        ),
),
位置类型模型中的关系部分

public function relations()
{
    // NOTE: you may need to adjust the relation name and the related
    // class name for the relations automatically generated below.
    return array(
                'locationlocationtype_rel' => array(self::BELONGS_TO, 'Locations', 'location_type_id'),
    );
}
那么:如何用location\u type替换location\u id

 array(           
        'name' => 'location_type_id', 
        'header' => 'Location Type'
        'value' => '$data->locationlocationtype_rel->location_type' // use relations property here
        ),