2015-04-08 81 views
0

而不是如果$ model-> id,如何將其更改爲$ model-> city_name?如何從關係模型yii2中檢索數據

$this->params['breadcrumbs'][] = ['label' => $model->cluster, 'url' => ['view', 'id' => $model->id]]; 

這裏是關係

public function getCityName() 
{ 
    return $this->hasOne(LibCities::className(),['city_code'=>'city_code']); 
} 

這是我tbl_targetcities enter image description here

,這是我lib_cities表 enter image description here

樣品查看..更改2這是從表lib_cities從tbl_target_Cities到CITY_NAME的ID。 enter image description here

回答

3

變化$model->id$model->cityName->city_namelabel屬性:

$this->params['breadcrumbs'][] = ['label' => $model->cityName->city_name, 'url' => ['view', 'id' => $model->id]];

+0

這是正確的。非常感謝。 – beginner

相關問題