如何从yii2中的关系模型中检索数据

时间:2015-04-08 01:16:21

标签: yii2

相反,如果$ model-> id,如何将其更改为$ model-> city_name?

$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

示例视图..将表格lib_cities中的ID从tbl_target_Cities更改为CITY_NAME。 enter image description here

1 个答案:

答案 0 :(得分:4)

$model->id属性$model->cityName->city_name更改为label

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

相关问题