我有 2 个模型:1 个用于网站,1 个用于产品;
产品知道他属于网站x;在表产品中,我有 website_id
在产品中我有关系:
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(
'relation_website' => array(self::BELONGS_TO,'Website','website_id'),
);
}
在产品模型的视图管理员中,我有:
$dataProvider = $model->search();
$dataProvider->pagination->pageSize = 100;
$this->widget('zii.widgets.grid.CGridView', array(
'id' => 'product-grid',
'dataProvider' => $dataProvider,
'filter' => $model,
'columns' => array(
'id',
'product',
'price',
'currency',
array(
'name' => 'website_id',
'value' => $model->relation_website->website_id,
),
/*
'website_id',
'url_id',
*/
array(
'class' => 'CButtonColumn',
'template' => '{update}{delete}',
),
),
));
我现在有这个结果:
1 笔记本电脑 Acer Aspire V3-571G-73614G50Maii cu 处理器 Intel® CoreTM i7-3610QM 2.30GHz,Ivy Bridge,4GB,500GB,nVidia GeForce GT 640M 2GB,Linpus,黑色 3099.99 RON 1 <- 这里的值
而不是最后一个我想打印http://www.eshop.com/,存储在网站表中的值,属于网站模型的表
1 笔记本电脑 Acer Aspire V3-571G-73614G50Maii cu 处理器 Intel® CoreTM i7-3610QM 2.30GHz,Ivy Bridge,4GB,500GB,nVidia GeForce GT 640M 2GB,Linpus,黑色 3099.99 RON http://www.domain.com/