我在gridviews中获得了基于外键关系的显示id.如何获取值而不是ID?我的gridview中的代码如下:
$criteria->compare('education.UniversityNameid',$this->UniversityName, true);
我在代码中的gridviews
array(
'name' => 'UniversityName',
'type' => 'raw',
'value'=>'(empty($data->education->UniversityNameid))? "" : Yii::app()->params["currencySymbol"]." ".$data->education->UniversityNameid',
),
解决方法:
你必须像你这样在你的模型“大学”中建立一个关系
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(
'UniversityName' => array(self::BELONGS_TO, 'University', 'UniversityNameid'),
);
}
谢谢你可以访问名称
$data->education->UniversityName