2017 © Pedro Peláez
 

library paginator

A simple PHP paginator

image

rgehan/paginator

A simple PHP paginator

  • Friday, April 21, 2017
  • by rgehan
  • Repository
  • 0 Watchers
  • 0 Stars
  • 5 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 4 Versions
  • 0 % Grown

The README.md

rgehan/paginator-php

This is a quick implementation of a paginator for a project, (*1)

Installation

Simply require it with composer:, (*2)

composer require rgehan/paginator

Usage


define('ITEMS_PER_PAGE', 3); // Gets the count of articles $articlesCount = 10; // You might want to load that from the database // Makes pagination $paginator = new Paginator($articlesCount, self::ITEMS_PER_PAGE); $paginator->setURLFormatString("http://localhost/articles?page=%d"); // Gets the page we want to access if(isset($_GET['page'])) $page = $paginator->getValidPage($_GET['page']); // Returns a page in the range of the existing pages else $page = 0; // Fetches the articles $startIndex = $page * self::ITEMS_PER_PAGE; $articles = do_sql_query("SELECT * FROM articles LIMIT " . $startIndex . ", " . ITEMS_PER_PAGE); // Pseudo-code for SQL query // Creates the pagination $pagination = $paginator->generateLinks($page); /* Let's say: $page = 2 Outputs: [ [ 'url' => 'http://localhost/articles?page=0', 'index' => 0, 'current' => false ],[ 'url' => 'http://localhost/articles?page=1', 'index' => 1, 'current' => false ],[ 'url' => 'http://localhost/articles?page=2', 'index' => 2, 'current' => true ],[ 'url' => 'http://localhost/articles?page=3', 'index' => 3, 'current' => false ], ... ] */

You can then pass the output of $paginator->generateLinks($page) to your view and render your links as you wish., (*3)

The Versions

21/04 2017

dev-master

9999999-dev

A simple PHP paginator

  Sources   Download

MIT

The Development Requires

by Renan GEHAN

21/04 2017

1.0.2

1.0.2.0

A simple PHP paginator

  Sources   Download

MIT

The Development Requires

by Renan GEHAN

19/04 2017

1.0.1

1.0.1.0

A simple PHP paginator

  Sources   Download

MIT

by Renan GEHAN

19/04 2017

1.0.0

1.0.0.0

A simple PHP paginator

  Sources   Download

MIT

by Renan GEHAN