PHP code example of componenta / http-pagination

1. Go to this page and download the library: Download componenta/http-pagination library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

componenta / http-pagination example snippets


use Componenta\Http\PaginatorUrlBuilder;

// Current request: /posts?tag=php&limit=20&offset=20
$builder = PaginatorUrlBuilder::fromRequest($request, defaultLimit: 20);

$next = $builder->nextUrl($paginator);
$prev = $builder->prevUrl($paginator);
$page = $builder->pageUrl(3, 20);

$builder = new PaginatorUrlBuilder($uri, offsetParam: 'skip', limitParam: 'take');

use Componenta\Http\ResourcePaginator;

$resource = new ResourcePaginator($paginator, $request->getUri());

return $resource->toArray();

$resource = new ResourcePaginator($paginator, $request->getUri(), ['count', 'next', 'results']);