0
我正在用Yii2構建一個REST API。通常情況下,請求響應看起來是這樣的:如何覆蓋Yii2中的REST序列化程序?
{
"items": [
{
"id": 1,
...
},
{
"id": 2,
...
},
...
],
"_links": {
"self": {
"href": "http://localhost/users?page=1"
},
"next": {
"href": "http://localhost/users?page=2"
},
"last": {
"href": "http://localhost/users?page=50"
}
},
"_meta": {
"totalCount": 1000,
"pageCount": 50,
"currentPage": 1,
"perPage": 20
}
}
我要重寫序列化,使得包含了「_meta」數組中的字段,而不是包含在陣列的根,即相同的水平「項目「和」_links「。我如何以及在哪裏做到這一點?
謝謝。
謝謝。這工作完美。爲了完成答案,我將新的MySerializer類放入application/components文件夾,然後放入MyController類中: 'class'=>'app \ components \ MySerializer', – Littlebob