获取 Yii2 中额外字段的所有属性



从extraFields((网址获取属性就像

organizations/6/location?expands=address,city (i have 10 attribute)

但是我怎样才能从extraFields((中一次获得所有这些

像这样的东西 组织/6/位置?展开=真或全部

这个托勒

public function actionIndex($id) {
$locations= Location::findAll($id);
return new ArrayDataProvider([
'allModels' => $locations,
'pagination' => false,
]);

这是我的模型代码

public function fields() {
return [
'id',
'display',
];
}
public function extraFields() {
return [
'address',
'city',
'state',
'country',
'zipcode',
'country_code',
'phone_number',
];
}

我真的不明白你的问题,但我认为你想这样做:

组织/6/位置?扩展=真实&地址=Myadresse&city=MyCity ....

你能给我们一些代码来帮助你吗?

您的 URL 中有拼写错误,应该是

expand=address,cityexpandS=address,city

请参阅 https://www.yiiframework.com/doc/guide/2.0/en/rest-resources#overriding-extra-fields

最新更新