public function fields()
{
return [
'field' => 'field',
];
}
public function extraFields()
{
return [
'users',
];
}
返回:
{ "field": "field", "users": { "id": 1, "name": "user" } }
如何排除ID?
public function extraFields()
{
return [
'users' => function($model){
return [
'name' => $model->users->name,
];
}
];
}
返回:
{ "field": "field", "users": { "name": null } }
如何正确填写名称字段或如何自定义字段输出过滤?
答案 0 :(得分:0)
选项可以覆盖用户模型中的field()方法:
public function fields()
{
$fields = parent::fields();
if ($something) {
unset($fields['id']);
}
return $fields;
}