使用GET列出記錄時,包含的extraField顯示正確的值 - rate_increase是額外的字段。Yii2其餘字段
{
"reseller_rateref": 263756,
"rate_increase": "50.00",
...
},
模型
class ResellerRateResource extends ResellerRate
{
public $rate_increase;
/*
* @return $fields array Filtered fields for API presentation
*/
public function fields()
{
$fields = array_merge(parent::fields(), ['rate_increase']);
return $fields;
}
查詢來獲取數據:
$query = $model::find()
->leftJoin('reseller_config', 'reseller_rate.resellerref = reseller_config.resellerref')
->select('reseller_rate.*, reseller_config.rate_increase AS rate_increase');
然而觀看單個記錄時,它始終顯示爲空。任何人都知道爲什麼?
不,我們不這樣做,因爲你沒有提供的信息 – delboy1978uk
更好.... – Kyle
是的,看到我的回答 – delboy1978uk