1

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?

4

1 回答 1

0

您可以获取您的数组并对其进行扩展,然后使用该修改后的数组创建一个新的 Paginator 对象。

于 2015-03-11T10:07:57.843 回答