Return JSON data with predefined key Yii2 -


i use yii2 , created restful api service. in app want return json data predefined key responses. example:

default respons:

[   {     "id": 1,     "title": "brooklyn"   },   {     "id": 2,     "title": "financial district"   },   {     "id": 4,     "title": "social district"   } ] 

but want smth that:

"data": [       {         "id": 1,         "title": "brooklyn"       },       {         "id": 2,         "title": "financial district"       },       {         "id": 4,         "title": "social district"       } ] 

you should customize rest serializer, in controller :

public $serializer = [     'class' => 'yii\rest\serializer',     'collectionenvelope' => 'data', ]; 

read more.


Comments

Popular posts from this blog

Command prompt result in label. Python 2.7 -

javascript - How do I use URL parameters to change link href on page? -

amazon web services - AWS Route53 Trying To Get Site To Resolve To www -