CodeIgniter v4.5 API

Pager
in package
implements PagerInterface

Class Pager

The Pager class provides semi-automatic and manual methods for creating pagination links and reading the current url's query variable, "page" to determine the current page. This class can support multiple paginations on a single page.

Tags
see
PagerTest

Table of Contents

Interfaces

PagerInterface
Expected behavior for a Pager

Properties

$config  : Pager
Our configuration instance.
$groups  : array<string|int, mixed>
The group data.
$only  : array<int, string>|null
List of only permitted queries
$segment  : array<string|int, mixed>
URI segment for groups if provided.
$view  : RendererInterface
The view engine to render the links with.

Methods

__construct()  : mixed
Constructor.
getCurrentPage()  : int
Returns the number of the current page of results.
getDetails()  : array<string|int, mixed>
Returns an array with details about the results, including total, per_page, current_page, last_page, next_url, prev_url, from, to.
getFirstPage()  : int
Determines the first page # that should be shown.
getLastPage()  : int|null
Returns the last page, if we have a total that we can calculate with.
getNextPageURI()  : string|null
Returns the full URI to the next page of results, or null.
getPageCount()  : int
Returns the total number of pages.
getPageURI()  : string|URI
Returns the URI for a specific page for the specified group.
getPerPage()  : int
Returns the number of results per page that should be shown.
getPreviousPageURI()  : string|null
Returns the full URL to the previous page of results, or null.
getTotal()  : int
Returns the total number of items in data store.
hasMore()  : bool
Tells whether this group of results has any more pages of results.
links()  : string
Handles creating and displaying the
makeLinks()  : string
Allows for a simple, manual, form of pagination where all of the data is provided by the user. The URL is the current URI.
only()  : self
Sets only allowed queries on pagination links.
setPath()  : $this
Sets the path that an aliased group of links will use.
setSegment()  : $this
Sets segment for a group.
simpleLinks()  : string
Creates simple Next/Previous links, instead of full pagination.
store()  : $this
Stores a set of pagination data for later display. Most commonly used by the model to automate the process.
calculateCurrentPage()  : void
Calculating the current page
displayLinks()  : string
Does the actual work of displaying the view file. Used internally by links(), simpleLinks(), and makeLinks().
ensureGroup()  : void
Ensures that an array exists for the group specified.

Properties

$config

Our configuration instance.

protected Pager $config

$groups

The group data.

protected array<string|int, mixed> $groups = []

$only

List of only permitted queries

protected array<int, string>|null $only

$segment

URI segment for groups if provided.

protected array<string|int, mixed> $segment = []

Methods

getCurrentPage()

Returns the number of the current page of results.

public getCurrentPage([string $group = 'default' ]) : int
Parameters
$group : string = 'default'
Return values
int

getDetails()

Returns an array with details about the results, including total, per_page, current_page, last_page, next_url, prev_url, from, to.

public getDetails([string $group = 'default' ]) : array<string|int, mixed>

Does not include the actual data. This data is suitable for adding a 'data' object to with the result set and converting to JSON.

Parameters
$group : string = 'default'
Return values
array<string|int, mixed>

getFirstPage()

Determines the first page # that should be shown.

public getFirstPage([string $group = 'default' ]) : int
Parameters
$group : string = 'default'
Return values
int

getLastPage()

Returns the last page, if we have a total that we can calculate with.

public getLastPage([string $group = 'default' ]) : int|null
Parameters
$group : string = 'default'
Return values
int|null

getNextPageURI()

Returns the full URI to the next page of results, or null.

public getNextPageURI([string $group = 'default' ][, bool $returnObject = false ]) : string|null
Parameters
$group : string = 'default'
$returnObject : bool = false
Return values
string|null

getPageCount()

Returns the total number of pages.

public getPageCount([string $group = 'default' ]) : int
Parameters
$group : string = 'default'
Return values
int

getPageURI()

Returns the URI for a specific page for the specified group.

public getPageURI([int|null $page = null ][, string $group = 'default' ][, bool $returnObject = false ]) : string|URI
Parameters
$page : int|null = null
$group : string = 'default'
$returnObject : bool = false
Return values
string|URI

getPerPage()

Returns the number of results per page that should be shown.

public getPerPage([string $group = 'default' ]) : int
Parameters
$group : string = 'default'
Return values
int

getPreviousPageURI()

Returns the full URL to the previous page of results, or null.

public getPreviousPageURI([string $group = 'default' ][, bool $returnObject = false ]) : string|null
Parameters
$group : string = 'default'
$returnObject : bool = false
Return values
string|null

getTotal()

Returns the total number of items in data store.

public getTotal([string $group = 'default' ]) : int
Parameters
$group : string = 'default'
Return values
int

hasMore()

Tells whether this group of results has any more pages of results.

public hasMore([string $group = 'default' ]) : bool
Parameters
$group : string = 'default'
Return values
bool

Handles creating and displaying the

public links([string $group = 'default' ][, string $template = 'default_full' ]) : string
Parameters
$group : string = 'default'
$template : string = 'default_full'

The output template alias to render.

Return values
string

Allows for a simple, manual, form of pagination where all of the data is provided by the user. The URL is the current URI.

public makeLinks(int $page, int|null $perPage, int $total[, string $template = 'default_full' ][, int $segment = 0 ][, string|null $group = 'default' ]) : string
Parameters
$page : int
$perPage : int|null
$total : int
$template : string = 'default_full'

The output template alias to render.

$segment : int = 0

(whether page number is provided by URI segment)

$group : string|null = 'default'

optional group (i.e. if we'd like to define custom path)

Return values
string

only()

Sets only allowed queries on pagination links.

public only(array<string|int, mixed> $queries) : self
Parameters
$queries : array<string|int, mixed>
Return values
self

setPath()

Sets the path that an aliased group of links will use.

public setPath(string $path[, string $group = 'default' ]) : $this
Parameters
$path : string
$group : string = 'default'
Return values
$this

setSegment()

Sets segment for a group.

public setSegment(int $number[, string $group = 'default' ]) : $this
Parameters
$number : int
$group : string = 'default'
Return values
$this

Creates simple Next/Previous links, instead of full pagination.

public simpleLinks([string $group = 'default' ][, string $template = 'default_simple' ]) : string
Parameters
$group : string = 'default'
$template : string = 'default_simple'
Return values
string

store()

Stores a set of pagination data for later display. Most commonly used by the model to automate the process.

public store(string $group, int $page, int|null $perPage, int $total[, int $segment = 0 ]) : $this
Parameters
$group : string
$page : int
$perPage : int|null
$total : int
$segment : int = 0
Return values
$this

calculateCurrentPage()

Calculating the current page

protected calculateCurrentPage(string $group) : void
Parameters
$group : string

Does the actual work of displaying the view file. Used internally by links(), simpleLinks(), and makeLinks().

protected displayLinks(string $group, string $template) : string
Parameters
$group : string
$template : string
Return values
string

ensureGroup()

Ensures that an array exists for the group specified.

protected ensureGroup(string $group[, int|null $perPage = null ]) : void
Parameters
$group : string
$perPage : int|null = null

        
On this page

Search results