如果与 REST 的其他参数合并,ActiveDataProvider 不返回实际数据 api - Yii2

ActiveDataProvider not returning actual data if merged with other params for REST api - Yii2

我制作了一个应用程序,它通过 rest api 向我的移动设备提供数据。 我有来自各种表的数据,这些数据基于它们之间通过键 (Foreign/Index) 建立的关系。

我正在使用 ActiveDataProvider 从表中提取所需数据。

$dataProvider = new ActiveDataProvider([
   'query'=>$query
]);

根据我设置的查询和 returning 数据,当我 return 时,我需要 JSON 格式的数据,效果很好,如下所示:

return $dataProvider;

我想要的是:

例如:

[
  "some_other_data":{
     -----
  },
  "dataProvider": {
    "device_id": "552255445511",
    "dated": "2016-03-15 23:00:04",
    "speed": "73.30",
    "power": null,
    "ignition": null,
    "ac": null,
    "address": "52",
    "latitude": "30.4575",
    "longitude": "76.1",
    "devices": {
      "vehicle_number": "UK 6S Z 5555",
      "vehicle_type": "0"
    }
  }
]

问题是当我 return 它是:

return array('some_other_data'=>$somedata, 'dataProvider'=>$dataProvider);

那么结果是这样的:

{
  "some_other_data": 0,
  "dataProvider": {
    "query": {
      "sql": null,
      "on": null,
      "joinWith": null,
      "select": null,
      "selectOption": null,
      "distinct": null,
      "from": null,
      "groupBy": null,
      "join": null,
      "having": null,
      "union": null,
      "params": [],
      "where": {
        "tk103_current_location.device_id": {
          "sql": null,
          "on": null,
          "joinWith": null,
          "select": [
            "device_id"
          ],
          "selectOption": null,
          "distinct": null,
          "from": null,
          "groupBy": null,
          "join": null,
          "having": null,
          "union": null,
          "params": [],
          "where": {
            "transporter_id": 22
          },
          "limit": null,
          "offset": null,
          "orderBy": null,
          "indexBy": null,
          "modelClass": "api\modules\v1\models\Tk103Devices",
          "with": null,
          "asArray": null,
          "multiple": null,
          "primaryModel": null,
          "link": null,
          "via": null,
          "inverseOf": null
        }
      },
      "limit": null,
      "offset": null,
      "orderBy": null,
      "indexBy": null,
      "modelClass": "api\modules\v1\models\Tk103CurrentLocation",
      "with": null,
      "asArray": null,
      "multiple": null,
      "primaryModel": null,
      "link": null,
      "via": null,
      "inverseOf": null
    },
    "key": null,
    "db": null,
    "id": null
  }
}

即ActiveDataProvider return在结果中使用类似于数据的模式,而不是实际结果。

请给我一个线索或提示如何强制这个 dataProvider return 实际数据,而不是它试图 return 数据的架构。

尝试

return array('some_other_data'=>$somedata, 'dataProvider'=>$dataProvider->getModels());