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

'hasOwnProperty' in javascript -

How to put a lock and transaction on table using spring 4 or above using jdbcTemplate and annotations like @Transactional? -

java - How to implement an entity bound odata action in olingo v4.3 -