2017 © Pedro Peláez
 

library paginate

Pagination library for PHPixie

image

phpixie/paginate

Pagination library for PHPixie

  • Friday, February 16, 2018
  • by dracony
  • Repository
  • 1 Watchers
  • 2 Stars
  • 11,121 Installations
  • PHP
  • 2 Dependents
  • 0 Suggesters
  • 2 Forks
  • 1 Open issues
  • 5 Versions
  • 6 % Grown

The README.md

Paginate

PHPixie Pagination library, (*1)

Build Status Test Coverage Code Climate HHVM Status, (*2)

Author Source Code Software License Total Downloads, (*3)

This is the base package for PHPixie Pagination that is split into several components., (*4)

// Initializing
$paginate = new \PHPixie\Paginate();

The base library cn only paginate arrays, there is an ORM extension available too, which we will look at further on. First let's see a usage example:, (*5)

// Array with a 100 items
$data = range(1, 100);

// Initialize the pager
// with 15 items per page
$pager = $paginate->arrayPager($data, 15);

// Set current page
$pager->setCurrentPager(3);

// A shorter way to do this:
$pager = $paginate->arrayPager($data, 15)
    ->setCurrentPage(3);

// Get some data
$pager->currentPage(); // 3
$pager->pageSize();    // 15
$pager->itemCount();   // 100
$pager->pageCount();   // 7 

// Get current items
$pager->currentItems();

// Check if page exists:
$pager->pageExists(1); // true

// Check if a page exists
// relative to the current one
$this->pageOffsetExists(-1); // true

// Get page number by relative offset
// Will return null if the page is missing
// In this case 4, since 3 is the current one
$this->getPageByOffset(1);

// Some shorthands,
// also return null if page missing
$this->next(); // 4
$this->previous(); // 2

A more interesting feature is getting pages adjacent to the current one, which is useful for rendering the pager., (*6)

// 15 items, split into 6 pages
$data = range(1, 18);
$pager = $paginate->arrayPager($data, 3);

$pager->setCurrentPage(3);

$pager->getAdjacent(3); // array(2, 3, 4);

$pager->setCurrentPage(1);
$pager->getAdjacent(2); // array(1, 2);

$pager->setCurrentPage(5);
$pager->getAdjacent(4); // array(3, 4, 5, 6);

ORM

First we need to build the ORM pagination library:, (*7)

$paginate = new \PHPixie\Paginate();
$paginateOrm = new \PHPixie\PaginateORM($paginate);

ORM pagination supports relationship preloading:, (*8)

$pager = $paginateOrm->queryPager($query, 15);

// Or with the relationships specified
$pager = $paginateOrm->queryPager($query, 15, array('items'));

It will also consider the limit and offset you specified for the query. This means if you limit the items in the query before creating the pager, only those items will be paged:, (*9)

$query->limit(100)->offset(10);
$pager = $paginateOrm->queryPager($query, 15);

// Only those 100 items
// are in the pager
$pager->itemCount(); // 100

The Versions

16/02 2018

dev-master

9999999-dev http://phpixie.com

Pagination library for PHPixie

  Sources   Download

BSD BSD-3-Clause

The Development Requires

pagination paginate

16/02 2018

3.1.1

3.1.1.0 http://phpixie.com

Pagination library for PHPixie

  Sources   Download

BSD-3-Clause

The Development Requires

pagination paginate

24/05 2016

3.1

3.1.0.0 http://phpixie.com

Pagination library for PHPixie

  Sources   Download

BSD

The Development Requires

pagination paginate

11/10 2015

3.0

3.0.0.0 http://phpixie.com

Pagination library for PHPixie

  Sources   Download

BSD

The Development Requires

pagination paginate

08/09 2015

2.x-dev

2.9999999.9999999.9999999-dev http://phpixie.com

Pagination module for PHPixie

  Sources   Download

BSD

The Requires

 

orm pagination