jdzm / jdz-paginator
A Simple paginator for PHP
Installs: 23
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
pkg:composer/jdzm/jdz-paginator
Requires
- php: >=5.4
Requires (Dev)
- phpunit/phpunit: >=5.0
This package is auto-updated.
Last update: 2025-10-07 21:20:46 UTC
README
JDZPaginator is a Simple implementation for creating data pagination.
Instalation
To install this package, run the command below and you will get the latest version
composer require jdzm/jdz-paginator
Usage
<?php
$products = array(
array('id' => 1,'nombre' => 'Producto 1','precio' => 100,'created_at' => date('Y-m-d')),
array('id' => 2,'nombre' => 'Producto 2','precio' => 200,'created_at' => date('Y-m-d')),
array('id' => 3,'nombre' => 'Producto 3','precio' => 250,'created_at' => date('Y-m-d')),
array('id' => 5,'nombre' => 'Producto 4','precio' => 350, 'created_at' => date('Y-m-d')),
array('id' => 6,'nombre' => 'Producto 5','precio' => 50, 'created_at' => date('Y-m-d'))
);
$pageNumber = 0; // Page number for current page
$size = 2; // Elements by page
$offset = $pageNumber * $size; // get offset
$countArray = sizeof($productos);
$products = array_slice($products, $offset, $size);
use Jdzm\JDZPaginator\Pagination\Paginator;
$paginator = new Paginator($pageNumber, $size, $countArray, $products);
header('Content-Type: application/json');
echo json_encode($paginator->paginate()); // GET DATA IN JSON FORMAT