final class PaginationState (View source)

Describes one requested page and derives its offsets, navigation state and page URLs.

Methods

__construct(int $currentPage, int $perPage, int $total, string $pageName, string $basePath, array $query = [])

Initializes page boundaries and the URL context preserved across navigation links.

int

Returns the one-based page selected for this result set.

int
int

Returns the number of rows assigned to each page.

int
int
total()

Returns the total number of rows in the result set.

int
string

Returns the query parameter name that carries the requested page.

string
int
offset()

Returns the zero-based row offset for the current page.

int
int

Returns the highest valid page, with one as the minimum.

int
bool

Reports whether the result set spans more than one page.

bool
bool

Reports whether a page before the current page exists.

bool
bool

Reports whether a page after the current page exists.

bool
int

Returns the closest valid page before the current page.

int
int

Returns the closest valid page after the current page.

int
string
url(int $page)

Builds a page URL while retaining non-empty query parameters from this state.

string
array
pages(int $maxPages = 5)

Returns a contiguous window of valid page numbers centered around the current page where possible.

array

Details

__construct

__construct(int $currentPage, int $perPage, int $total, string $pageName, string $basePath, array $query = [])

Initializes page boundaries and the URL context preserved across navigation links.

Parameters

int $currentPage
int $perPage
int $total
string $pageName
string $basePath
array $query

currentPage

int currentPage()

Returns the one-based page selected for this result set.

Return Value

int

perPage

int perPage()

Returns the number of rows assigned to each page.

Return Value

int

total

int total()

Returns the total number of rows in the result set.

Return Value

int

pageName

string pageName()

Returns the query parameter name that carries the requested page.

Return Value

string

offset

int offset()

Returns the zero-based row offset for the current page.

Return Value

int

lastPage

int lastPage()

Returns the highest valid page, with one as the minimum.

Return Value

int

hasPages

bool hasPages()

Reports whether the result set spans more than one page.

Return Value

bool

hasPrev

bool hasPrev()

Reports whether a page before the current page exists.

Return Value

bool

hasNext

bool hasNext()

Reports whether a page after the current page exists.

Return Value

bool

prevPage

int prevPage()

Returns the closest valid page before the current page.

Return Value

int

nextPage

int nextPage()

Returns the closest valid page after the current page.

Return Value

int

url

string url(int $page)

Builds a page URL while retaining non-empty query parameters from this state.

Parameters

int $page

Return Value

string

pages

array pages(int $maxPages = 5)

Returns a contiguous window of valid page numbers centered around the current page where possible.

Parameters

int $maxPages

Return Value

array