PHP code example of anh / paginator

1. Go to this page and download the library: Download anh/paginator 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/ */

    

anh / paginator example snippets




use Anh\Paginator\Paginator;

$query = /* ORM Query or QueryBuilder for fetching users */;

$paginator = new Paginator();
$users = $paginator->paginate($query, 1, 10);

foreach ($users as $user) {
    // do something with user
}



use Anh\Paginator\Paginator;
use Anh\Paginator\Adapter\ArrayAdapter;

$data = array(/* elements */);

$paginator = new Paginator();
$elements = $paginator->paginate($data, 3, 20, array('preserveKeys' => true));

foreach ($elements as $key => $element) {
    // do something with element
}



use Anh\Paginator\Paginator;
use Anh\Paginator\AdapterResolver;

$adapterResolver = new AdapterResolver();
$adapterResolver->addAdapter('Some\Custom\Adapter1');
$adapterResolver->addAdapter('Some\Custom\Adapter2');

$paginator = new Paginator($adapterResolver);
$elements = $paginator->paginate($data, $pageNumber, $elementsPerPage);

foreach ($elements as $element) {
    // do something with element
}



use Anh\Paginator\Paginator;
use Anh\Paginator\View\AdaptiveView;

$paginator = new Paginator();
$posts = $paginator->paginate(/* ... */);

$view = new AdaptiveView();
$view->setTemplates(array(/* templates */));
$view->setOptions(array(/* options */));

echo $view->render($posts, '/some/url/page-%page%', array(/* options */));
bash
$ php composer.phar