0

从 extraFields() url 获取属性就像

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

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

像这样的组织/6/location?expands=true 或 all

这个控制器

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',
    ];
}
4

2 回答 2

0

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

组织/6/location?expands=true&address=myadresse&city=mycity ....

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

于 2020-06-16T12:22:09.477 回答
0

你的网址有错字,应该是

expand=address,city不是expandS=address,city

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

于 2020-06-18T04:37:34.597 回答