jdzm/jdz-paginator

A Simple paginator for PHP

1.1 2022-04-06 17:21 UTC

This package is auto-updated.

Last update: 2024-05-07 18:23:43 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