Pagination
class Pagination
Holds pagination state and builds page URLs. Rendering is delegated to a PaginationRenderer so the same object can drive Bootstrap, Tailwind, a custom layout, or a React view (via toArray()).
Properties
| protected int | $currentPage | ||
| protected int | $limit | ||
| protected int | $totalItems | ||
| protected array | $query | Query params preserved in every page link (search, filters, sort). |
|
| protected string | $path | Base path for links. Empty string = relative to the current URL. |
|
| protected string | $pageName | Name of the page query parameter. |
|
| protected int | $window | Number of page links shown on each side of the current page. |
|
| static protected PaginationRenderer|null | $defaultRenderer | Renderer used by render() when none is passed. |
Methods
Constructor for Pagination class
Convenience factory that reads the page number from the request.
Retrieves and validates the current page from the GET request.
Preserve the filter's active query params (search term, filters, sort) in every generated page link.
Preserve arbitrary query params in every generated page link.
Set a base path for links (e.g. '/admindashboard').
Change the page query parameter name (useful for two lists on one page).
Number of page links on each side of the current page.
Set the renderer used when render() is called without one.
No description
No description
No description
No description
Calculates offset needed for pagination.
Returns total number of pages we need to handle.
True when there is more than one page (renderers output nothing otherwise).
No description
No description
1-based index of the first item on this page (0 when empty).
1-based index of the last item on this page (0 when empty).
Builds the URL for a page, keeping search/filter/sort params intact.
No description
No description
Sliding window of page numbers. null marks a gap (render as an ellipsis).
Builds parameters for pagination query (original API, kept for existing callers).
Renders the controls with the given renderer, or the default one.
Serializable state for React views or JSON APIs.
Renders Bootstrap 5 pagination controls (original static API).
Renders pagination summary.
Details
at line 40
__construct(int $currentPage = 1, int $limit = 10, int $totalItems = 0)
Constructor for Pagination class
at line 55
static Pagination
fromRequest(object $request, int $limit, int $totalItems)
Convenience factory that reads the page number from the request.
at line 66
static int
currentPage(object $request, string $pageName = 'page')
Retrieves and validates the current page from the GET request.
at line 83
Pagination
withFilter(SearchFilter $filter)
Preserve the filter's active query params (search term, filters, sort) in every generated page link.
at line 88
Pagination
withQuery(array $query)
Preserve arbitrary query params in every generated page link.
at line 95
Pagination
withPath(string $path)
Set a base path for links (e.g. '/admindashboard').
at line 101
Pagination
withPageName(string $pageName)
Change the page query parameter name (useful for two lists on one page).
at line 107
Pagination
withWindow(int $window)
Number of page links on each side of the current page.
at line 113
static void
setDefaultRenderer(PaginationRenderer $renderer)
Set the renderer used when render() is called without one.
at line 121
int
currentPageNumber()
No description
at line 122
int
limit()
No description
at line 123
int
totalItems()
No description
at line 124
string
pageName()
No description
at line 131
int
offset()
Calculates offset needed for pagination.
at line 140
int
totalPages()
Returns total number of pages we need to handle.
at line 145
bool
hasPages()
True when there is more than one page (renderers output nothing otherwise).
at line 149
bool
onFirstPage()
No description
at line 150
bool
onLastPage()
No description
at line 153
int
firstItem()
1-based index of the first item on this page (0 when empty).
at line 158
int
lastItem()
1-based index of the last item on this page (0 when empty).
at line 172
string
url(int $page)
Builds the URL for a page, keeping search/filter/sort params intact.
at line 177
string|null
previousPageUrl()
No description
at line 181
string|null
nextPageUrl()
No description
at line 191
array
pageRange()
Sliding window of page numbers. null marks a gap (render as an ellipsis).
Example for page 10 of 20, window 2: [1, null, 8, 9, 10, 11, 12, null, 20]
at line 219
array
queryParams(SearchFilter $filter)
Builds find() params from a SearchFilter plus limit/offset.
at line 235
array
paginationParams(mixed $conditions = '', array $bind = [], string $order = '')
Builds parameters for pagination query (original API, kept for existing callers).
at line 253
string
render(PaginationRenderer|null $renderer = null)
Renders the controls with the given renderer, or the default one.
at line 261
array
toArray()
Serializable state for React views or JSON APIs.
at line 285
static string
pagination(int $current_page, int $total_pages, string $base_url = '?page=')
deprecated
deprecated
Renders Bootstrap 5 pagination controls (original static API).
at line 295
string
paginationSummary(string $noun)
Renders pagination summary.