PHP code example of viloveul / pagination

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

    

viloveul / pagination example snippets




$parameter = new Viloveul\Pagination\Parameter('search', $_GET);

// $paremeter->setConditions([]);
// $parameter->setCurrentPage(1);
// $parameter->setOrderBy('id');
// $parameter->setSortOrder('asc');
// $parameter->setPageSize(20);

$pagination = new Viloveul\Pagination\Builder($parameter);
$pagination->with(function ($conditions, $size, $page, $order, $sort) use ($parameter) {
    $model = new YourUserModelSample();
    foreach ($conditions as $key => $value) {
        $model->where($key, 'LIKE', "%{$value}%");
    }
    // set total results
    $total = $model->count();
    // set result data array
    $result = $model->orderBy($order, $sort)->skip(($page * $size) - $size)->take($size)->get();

    return new Viloveul\Pagination\ResultSet($total, $result->toArray());
});

var_dump($pagination->getMeta());
var_dump($pagination->getData());