我的数据库结构
部门表包含
医生表包含
Doctor.php //型号名称
public function fields() {
return [
'doctor_id',
'd_name',
'email',
'phone',
'speciality',
'department' => function ($model) {
return $model->department->department; // Return related model property, correct according to your structure
},
'qualification',
'profile_image',
'experience',
];
}
web.php
[
'class' => 'yii\rest\UrlRule',
'controller' => ['doctor','department'],
],
JSON数据
[
{
"doctor_id":1,
"d_name":"Saurabh Joshi",
"email":"****@gmail.com",
"phone":0,
"speciality":"1",
"department_id":"1",
"qualification":"M.S. (General Surgery) – Marathwada University\n MBBS – Marathwada University",
"profile_image":"Saurabh_Joshi1-1439384488.jpg",
"experience":""
}
]
当我从医生表中获取数据以在表单上显示时,我想要department name
而不是department_id
。