1

I have created a resource that when fetched GET /resource/{id} returns a response (on success/found) with the following template:

Resource:

{
    "name": "Name",
    "code" "Code",
    "_embedded" : {
        "foos" : [{
            "name" : "bar1",
            "value" : "value1",
       },
       {
            "name" : "bar2",
            "value" : "value2",
       }]
    }

}

Code for fetch($id)

fetch($id){

    $resource = ... // query resource

    $resourceEntity = new ResourceEntity();
    $resourceEntity->exchangeArray($resource);

    $foos = ... // query foos
    $fooAdapter = new Adapter\ArrayAdapter($foos);
    $fooCollection = new Foo\FooCollection($fooAdapter);

    $resourceEntity->foos = $fooCollection;

    return $resourceEntity;

}

My problem is that when the fooCollection consists of more than 10 entities only 10 entities gets rendered in response.

Things I tried so far:

  • I checked if this has to do with the default page size of the FooCollection in the module.config.php but the setting is equal to 25 in my case.

  • I tried to look at the Zend documentation to see if I can force the Paginator to be set to -1, since by doing so (I think) will not paginate the result.

  • I tried not used a Collection to just a plain array for the "foos" property. I showed all the results but it did not render each foo entities as a HAL entity

leonard.javiniar
  • 539
  • 8
  • 25

1 Answers1

1

Finally!

The Collections in Apigility extends from Zend\Paginator\Paginator. As per the docs, the default page size (or item count per page) of a paginator is 10.

All I have to do is to set the page size to -1 using $paginator->setItemCountPerPage(-1) to tell the paginator to include all entities in a single page.

leonard.javiniar
  • 539
  • 8
  • 25