【问题标题】:Get all attributes of extraFields in Yii2获取 Yii2 中 extraFields 的所有属性
【发布时间】:2020-06-16 11:07:39
【问题描述】:

从 extraFields() url 获取属性就像

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

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

类似 organizations/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',
    ];
}

【问题讨论】:

    标签: api rest yii2 yii2-advanced-app yii2-api


    【解决方案1】:

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

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

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

    【讨论】:

    • 现在检查我的问题@Jonathan Delean
    • 您开发 API 还是尝试使用它?你能提供我们你的后端和前端的代码吗?
    • 我正在开发api
    【解决方案2】:

    你的网址有错别字,应该是

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-05-30
      • 1970-01-01
      • 2013-04-05
      • 1970-01-01
      • 2012-06-09
      相关资源
      最近更新 更多