PageIndex
in package
implements
Stringable
Constructs a page list.
E.g.: 1 ... 6 7 [8] 9 10 ... 15.
Table of Contents
Interfaces
- Stringable
Properties
- $base_url : string
- $num_items : int
- $num_per_page : int
- $short_format : bool
- $show_prevnext : bool
- $start : int
- $base_link : string
- $current_page : string
- $current_page_num : int
- $expand_pages : string
- $extra_after : string
- $extra_before : string
- $last_page_num : int
- $last_page_value : int
- $next_page : string
- $page : string
- $page_contiguous : int
- $previous_page : string
- $start_invalid : bool
Methods
- __construct() : mixed
- Constructor.
- __toString() : string
- Finalizes and returns the page index links.
- setTemplateOverrides() : void
- Sets template overrides.
- expandPages() : string
- Show the ... for the hidden pages.
- firstPage() : string
- Show the first page in the list.
- fixStart() : int
- Fixes $start if it is out of bounds or not a multiple of $this->num_per_page.
- lastPage() : string
- Show the last page in the list.
- nextPage() : string
- Show the "next page" link.
- pageRange() : string
- Shows a range of pages.
- prevPage() : string
- Show the "prev page" link.
Properties
$base_url
public
string
$base_url
The base URL for all the page index links.
$num_items
public
int
$num_items
The total number of items in the overall paginated list.
$num_per_page
public
int
$num_per_page
How many items to show per page.
$short_format
public
bool
$short_format
= false
Whether to use "url.offset" format instead of "url;start=offset" format.
$show_prevnext
public
bool
$show_prevnext
= true
Set this to false to hide the previous page and next page arrow links.
$start
public
int
$start
The value we are starting at.
Should be the number of a specific item in the overall paginated list.
$base_link
private
string
$base_link
Template string used to create links to specific pages.
This is built by inserting $this->base_url into $this->page.
$current_page
private
string
$current_page
= '<span class="current_page">%1$d</span> '
Template string for the current page.
$current_page_num
private
int
$current_page_num
The number of the page that the user is currently viewing.
$expand_pages
private
string
$expand_pages
= '<span class="expand_pages" onclick="expandPages(this, {LINK}, {FIRST_PAGE}, {LAST_PAGE}, {PER_PAGE});"> ... </span>'
Template string for the "..." bit in long page indexes.
$extra_after
private
string
$extra_after
= ''
Template string for the bit to show after the page links end.
$extra_before
private
string
$extra_before
= '<span class="pages">{txt_pages}</span>'
Template string for the bit to show before the page links begin.
$last_page_num
private
int
$last_page_num
The number of the last page.
$last_page_value
private
int
$last_page_value
Item number of the first item on the last page.
$next_page
private
string
$next_page
= '<span class="main_icons next_page"></span>'
Template string for next page arrow link.
$page
private
string
$page
= '<a class="nav_page" href="{URL}">%2$s</a> '
Template string for links to numbered pages.
$page_contiguous
private
int
$page_contiguous
How many contiguous pages to show in the middle when using the compact page index.
For example: 3 to display: 1 ... 7 [8] 9 ... 15 5 to display: 1 ... 6 7 [8] 9 10 ... 15
$previous_page
private
string
$previous_page
= '<span class="main_icons previous_page"></span>'
Template string for previous page arrow link.
$start_invalid
private
bool
$start_invalid
Tracks whether the requested $start value was out of bounds.
Methods
__construct()
Constructor.
public
__construct(string $base_url, int &$start, int $num_items, int $num_per_page[, bool $short_format = false ][, bool $show_prevnext = true ][, array<string|int, mixed> $template_overrides = [] ]) : mixed
-
short_format causes it to use "url.page" instead of "url;start=page".
-
very importantly, cleans up the start value passed, and forces it to be a multiple of num_per_page.
-
checks that start is less than num_items.
-
base_url should be the URL without any start parameter on it.
-
uses the compactTopicPagesEnable and compactTopicPagesContiguous settings to decide how to display the menu.
Parameters
- $base_url : string
-
The basic URL to be used for each link.
- $start : int
-
The start position, by reference. If this is not a multiple of the number of items per page, it is sanitized to be so and the value will persist upon the function's return.
- $num_items : int
-
The total number of items you are paginating for.
- $num_per_page : int
-
The number of items to be displayed on a given page. $start will be forced to be a multiple of this value.
- $short_format : bool = false
-
Whether to use "url.offset" instead of "url;start=offset". Default: false.
- $show_prevnext : bool = true
-
Whether the Previous and Next links should be shown. Default: true.
- $template_overrides : array<string|int, mixed> = []
-
Array of template strings to override defaults. Supported keys: extra_before, previous_page, current_page, page, expand_pages, next_page, extra_after.
__toString()
Finalizes and returns the page index links.
public
__toString() : string
Return values
stringsetTemplateOverrides()
Sets template overrides.
public
setTemplateOverrides([array<string|int, mixed> $template_overrides = [] ]) : void
Parameters
- $template_overrides : array<string|int, mixed> = []
-
Array of template strings to override defaults. Supported keys: extra_before, previous_page, current_page, page, expand_pages, next_page, extra_after.
expandPages()
Show the ... for the hidden pages.
protected
expandPages([bool $after = false ]) : string
Used when compact pages are turned on.
If $after is false, does the one near the start: (prev page 1 >...< 6 7 [8] 9 10 ... 15 next page)
If $after is true, does the one near the end: (prev page 1 ... 6 7 [8] 9 10 >...< 15 next page)
Parameters
- $after : bool = false
-
If true, do the one near the end.
Return values
stringfirstPage()
Show the first page in the list.
protected
firstPage() : string
(prev page >1< ... 6 7 [8] 9 10 ... 15)
Return values
stringfixStart()
Fixes $start if it is out of bounds or not a multiple of $this->num_per_page.
protected
fixStart(int $start) : int
Parameters
- $start : int
-
The start value.
Return values
int —The fixed start value.
lastPage()
Show the last page in the list.
protected
lastPage() : string
(prev page 1 ... 6 7 [8] 9 10 ... >15< next page)
Return values
stringnextPage()
Show the "next page" link.
protected
nextPage() : string
(prev page 1 ... 6 7 [8] 9 10 ... 15 >next page<)
Return values
stringpageRange()
Shows a range of pages.
protected
pageRange(int $min, int $max) : string
Parameters
- $min : int
-
The lowest page number to show.
- $max : int
-
The highest page number to show.
Return values
stringprevPage()
Show the "prev page" link.
protected
prevPage() : string
(>prev page< 1 ... 6 7 [8] 9 10 ... 15 next page)