我有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台笔记本电脑宏碁Aspire V3-571G-73614G50Maii cu处理器英特尔®酷睿™i7-3610QM 2.30GHz,Ivy Bridge,4GB,500GB,nVidia GeForce GT 640M 2GB,Linpus,黑色3099.99 RON 1< - 此值
而不是最后1个我要打印http://www.eshop.com/,存储在网站表中的值,属于网站模型的表
1台笔记本电脑宏碁Aspire V3-571G-73614G50Maii cu处理器英特尔®酷睿™i7-3610QM 2.30GHz,Ivy Bridge,4GB,500GB,nVidia GeForce GT 640M 2GB,Linpus,黑色3099.99 RON http://www.domain.com/
答案 0 :(得分:1)
看起来你需要这样的东西:
...
'value' => '$data->relation_website->name'
...
blog tutorial中有一个类似的例子,每个Yii开发者都必须阅读