Hateoas icon indicating copy to clipboard operation
Hateoas copied to clipboard

Adding a paging factory (KnpPaginatorFactory) for users of the paginator components of KNP -components

Open skineur opened this issue 9 years ago • 6 comments

How to use with Knp-Components Pager

use Hateoas\Representation\Factory\KnpPaginatorFactory;
use Hateoas\Configuration\Route;
use new Knp\Component\Pager\Paginator;

    // KnpPaginator component
    $pager = Paginator();
    $paginated = $pager->paginate($some, 1, 10);

    $factory = new KnpPaginatorFactory();
    $paginatedCollection= $factory->createRepresentation($paginated, new Route('my_route_name', array()));

    $json = $hateoas->serialize($paginatedCollection, 'json');
    $xml  = $hateoas->serialize($paginatedCollection, 'xml');

skineur avatar Dec 11 '15 10:12 skineur

Is this lib still maintained?

willdurand avatar Dec 11 '15 13:12 willdurand

this lib is maintained by KnpLabs. On symfony bundle it exist KnpPaginatorBundle based on this lib

skineur avatar Dec 11 '15 16:12 skineur

Alright. So let's fix the tests first, and then squash the commits so that we can get this merged :)

willdurand avatar Dec 16 '15 08:12 willdurand

Looks good!

This can be helpful for the timeline bundle that ships with knp paginator support: https://github.com/stephpy/timeline-bundle/blob/master/Resources/doc/pagination.markdown

adrienbrault avatar Jan 21 '16 14:01 adrienbrault

I saw a issue that talked about how to integrate knp paginator to create a representation of collection. Now it is true that it is not very useful on this library.

Thank you I will rather create a gist

skineur avatar Jan 22 '16 13:01 skineur

I saw a issue that talked about how to integrate knp paginator to create a representation of collection. Now it is true that it is not very useful on this library.

hi, @skineur what is the issue you're talking about? why this hasn't been merged? I would found it quite useful

jcornide avatar Apr 28 '17 08:04 jcornide