PHP Class Pagination

Show file Open project: getkirby/toolkit Class Usage Examples

Public Properties

Property Type Description
$defaults configuration

Protected Properties

Property Type Description
$count total count of items
$limit the number of displayed rows
$offset the offset for the slice function
$options options
$page the current page
$pages the total number of pages
$rangeEnd the range end for ranged pagination
$rangeStart the range start for ranged pagination

Public Methods

Method Description
__construct ( mixed $count, integer $limit, array $params = [] ) Constructor
__debuginfo ( ) : array Improved var_dump() output
countItems ( ) : integer Returns the total number of items in the collection
countPages ( ) : integer Returns the total number of pages
firstPage ( ) : integer Returns the number of the first page
firstPageURL ( ) : string Returns the url for the first page
hasNextPage ( ) : boolean Checks if there's a next page
hasPages ( ) : boolean Checks if multiple pages are needed or if the collection can be displayed on a single page
hasPrevPage ( ) : boolean Checks if there's a previous page
isFirstPage ( ) : boolean Checks if the current page is the first page
isLastPage ( ) : boolean Checks if the current page is the last page
items ( ) : integer Alternative for countItems()
lastPage ( ) : integer Returns the number of the last page
lastPageURL ( ) : string Returns the url for the last page
limit ( ) : integer Returns the chosen limit This is used for the slice() method together with the offset to get the correct items from collections
nextPage ( ) : integer Returns the number of the next page
nextPageURL ( ) : string Returns the url for the next page
numEnd ( ) : integer Returns the index number of the last item on the current page Can be used to display something like "Currently showing 1 - 10 of 123 items"
numStart ( ) : integer Returns the index number of the first item on the current page Can be used to display something like "Currently showing 1 - 10 of 123 items"
offset ( ) : integer Returns the current offset This is used for the slice() method together with the limit to get the correct items from collections
page ( ) : integer Returns the current page number
pageURL ( integer $page ) : string Returns a page url for any given page number
pages ( ) : integer Alternative for countPages()
prevPage ( ) : integer Returns the number of the previous page
prevPageURL ( ) : string Returns the url for the previous page
range ( $range = 5 ) : array Creates a range of page numbers for Google-like pagination
rangeEnd ( ) : integer Returns the last page of the created range
rangeStart ( ) : integer Returns the first page of the created range
redirect ( ) Redirects to an error page if the redirect option is set and the pagination is beyond the allowed boundaries
toArray ( ) : array Returns the most important pagination data into a readable array

Method Details

__construct() public method

Constructor
public __construct ( mixed $count, integer $limit, array $params = [] )
$count mixed Either an integer or a Collection
$limit integer The number of items per page
$params array Additional parameters to control the pagination object

__debuginfo() public method

Improved var_dump() output
public __debuginfo ( ) : array
return array

countItems() public method

Returns the total number of items in the collection
public countItems ( ) : integer
return integer

countPages() public method

Returns the total number of pages
public countPages ( ) : integer
return integer

firstPage() public method

Returns the number of the first page
public firstPage ( ) : integer
return integer

firstPageURL() public method

Returns the url for the first page
public firstPageURL ( ) : string
return string

hasNextPage() public method

Checks if there's a next page
public hasNextPage ( ) : boolean
return boolean

hasPages() public method

Checks if multiple pages are needed or if the collection can be displayed on a single page
public hasPages ( ) : boolean
return boolean

hasPrevPage() public method

Checks if there's a previous page
public hasPrevPage ( ) : boolean
return boolean

isFirstPage() public method

Checks if the current page is the first page
public isFirstPage ( ) : boolean
return boolean

isLastPage() public method

Checks if the current page is the last page
public isLastPage ( ) : boolean
return boolean

items() public method

Alternative for countItems()
public items ( ) : integer
return integer

lastPage() public method

Returns the number of the last page
public lastPage ( ) : integer
return integer

lastPageURL() public method

Returns the url for the last page
public lastPageURL ( ) : string
return string

limit() public method

Returns the chosen limit This is used for the slice() method together with the offset to get the correct items from collections
public limit ( ) : integer
return integer

nextPage() public method

Returns the number of the next page
public nextPage ( ) : integer
return integer

nextPageURL() public method

Returns the url for the next page
public nextPageURL ( ) : string
return string

numEnd() public method

Returns the index number of the last item on the current page Can be used to display something like "Currently showing 1 - 10 of 123 items"
public numEnd ( ) : integer
return integer

numStart() public method

Returns the index number of the first item on the current page Can be used to display something like "Currently showing 1 - 10 of 123 items"
public numStart ( ) : integer
return integer

offset() public method

Returns the current offset This is used for the slice() method together with the limit to get the correct items from collections
public offset ( ) : integer
return integer

page() public method

Returns the current page number
public page ( ) : integer
return integer

pageURL() public method

Returns a page url for any given page number
public pageURL ( integer $page ) : string
$page integer The page number
return string The url

pages() public method

Alternative for countPages()
public pages ( ) : integer
return integer

prevPage() public method

Returns the number of the previous page
public prevPage ( ) : integer
return integer

prevPageURL() public method

Returns the url for the previous page
public prevPageURL ( ) : string
return string

range() public method

Creates a range of page numbers for Google-like pagination
public range ( $range = 5 ) : array
return array

rangeEnd() public method

Returns the last page of the created range
public rangeEnd ( ) : integer
return integer

rangeStart() public method

Returns the first page of the created range
public rangeStart ( ) : integer
return integer

redirect() public method

Redirects to an error page if the redirect option is set and the pagination is beyond the allowed boundaries
public redirect ( )

toArray() public method

Returns the most important pagination data into a readable array
public toArray ( ) : array
return array

Property Details

$count protected property

total count of items
protected $count

$defaults public static property

configuration
public static $defaults

$limit protected property

the number of displayed rows
protected $limit

$offset protected property

the offset for the slice function
protected $offset

$options protected property

options
protected $options

$page protected property

the current page
protected $page

$pages protected property

the total number of pages
protected $pages

$rangeEnd protected property

the range end for ranged pagination
protected $rangeEnd

$rangeStart protected property

the range start for ranged pagination
protected $rangeStart