2013-12-01 3 views
0

У меня есть две реляционные таблицы: местоположение & location_types.CGridView с реляционными таблицами

Расположение

- location_id 
    - location_name 
    - location_type_id 

Location_types

- location_type_id 
- location_type 

И я сделал вид с виджетом CGridView, все работает отлично, даже поле Filer работает, за исключением того, в столбце LOCATION_TYPE отображается только location_type_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' 
     ), 
), 

Отношение часть от модели Location_types

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_type_id с LOCATION_TYPE?

ответ

0
array(   
     'name' => 'location_type_id', 
     'header' => 'Location Type' 
     'value' => '$data->locationlocationtype_rel->location_type' // use relations property here 
     ), 
Смежные вопросы