In a Zend Framework & Apiglity driven application I'm using Zend\Paginator\Paginator for my collection objects. A Paginator object contains a ResultSet, so flat data structures like:
{
"project": [
{
"id": "1",
"title": "...",
...
},
...
]
}
The result output after the processing it by the Hal REST controller plugin / view helper (ZF\Hal\Plugin\Hal) looks like this:
{
"_links": {...},
"_embedded": {
"project": [
{
"id": "1",
"title": "...",
...
},
...
]
},
"page_count": 3,
"page_size": 25,
"total_items": 72
}
Now, I want to nest a new level to it, e.g. every project should contain a list of images. The result output should look as follows:
{
"_links": {...},
"_embedded": {
"project": [
{
"id": "1",
"title": "...",
"_embedded": {
"images": [
{
"id": "1",
"src": "...",
...
},
...
]
}
},
...
]
},
"page_count": 3,
"page_size": 25,
"total_items": 72
}
I know, how to get an array copy of the data and extend it. But I have to return the Paginator object itselft.
(How) Can Zend\Paginator\Paginator's data be modified?
You can get your array and extend it and then create a new Paginator object with that modified array.