N
N
Nikita Samokhvalov2015-03-20 15:30:13
Yii
Nikita Samokhvalov, 2015-03-20 15:30:13

How to display an array in a REST application through ActiveDataProvider?

There are two models: Text and Tags. There are connections between them. The REST application's response to a request for the Text model should be something like this:

"items": [
     {
          "id": "1",
          "name": "Title",
          "desc": "Description",
          "active": 1,
          "tags": [ // Это данные из модели Tags
               {
                    "id": 1,
                    "name": "Test tag"
               }
          ]
     },
     …
]

The REST application issues a response through the ActiveDataProvider:
return new ActiveDataProvider([
     'query' => $modelClass::find()->with('tags')
]);

But there is no tags array in the application response :-( If you add the arArray() ('query' => $modelClass::find()->with('tags')->asArray()) method to the query, then the array will appear, but, for example, field customization will stop working in the Text model.In
general, I ask you to help me understand why it does not work and how to solve such problems.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
Nikita Samokhvalov, 2015-03-20
@niksamokhvalov

I read the doc inattentively :-( It turns out that all you had to do was pass the expand=tags GET parameter in the request.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question