Documentation

Pagination
in package

Pagination class

This class is used to generate pagination links for a given set of results.

Table of Contents

Properties

$currentNumberOfRecords  : int
Represents the current number of records in the pagination.
$currentPage  : int
Represents the current page number.
$currentPageDefinedByUser  : int|null
$db  : Db
Database connection object.
$numberOfPages  : int
Represents the number of pages in the pagination.
$paginationOptions  : PaginationOptions
Options
$recordsPerPage  : int
$totalRecordsCount  : int
The total number of records in the pagination.
$view  : View
Represents a Pagination object.

Methods

__construct()  : mixed
Constructor for the Pagination class.
fetch()  : mixed
Fetches the next row from a result set and returns it according to the $fetch_parameters format
fetchAll()  : mixed
Fetches all rows from a result set and return them according to the $fetch_parameters format
getCurrentNumberOfRecords()  : int
Returns the current number of records.
getCurrentPage()  : int
Retrieves the current page number.
getDb()  : Db
Get the database instance.
getNumberOfPages()  : int
Returns the number of pages.
getRecordsPerPage()  : int
Get the number of records to display per page.
getTotalRecordsCount()  : int
Returns the total number of records in the dataset.
pagine()  : string
Build pagination
select()  : self
Selects data from the database.
setCurrentPage()  : void
Sets the current page number and overrides the querystring.
setOptions()  : void
Sets the options for pagination.
setRecordsPerPage()  : self
Sets the number of records to display per page.
removePreviousQuerystring()  : string
Removes any previous querystring parameters from the URL.

Properties

$currentNumberOfRecords

Represents the current number of records in the pagination.

private int $currentNumberOfRecords

$currentPage

Represents the current page number.

private int $currentPage

The current page number.

$currentPageDefinedByUser

private int|null $currentPageDefinedByUser = null

$numberOfPages

Represents the number of pages in the pagination.

private int $numberOfPages

The number of pages in the pagination.

$recordsPerPage

private int $recordsPerPage = 10

The number of records to display per page.

$totalRecordsCount

The total number of records in the pagination.

private int $totalRecordsCount = 0

$view

Represents a Pagination object.

private View $view

The view object associated with the Pagination.

Methods

__construct()

Constructor for the Pagination class.

public __construct(Db $db, PaginationOptions $paginationOptions, View $view, int $recordsPerPage) : mixed
Parameters
$db : Db

The database connection object.

$paginationOptions : PaginationOptions

The pagination options object.

$view : View
$recordsPerPage : int

fetch()

Fetches the next row from a result set and returns it according to the $fetch_parameters format

public fetch([int $fetch_parameters = PDO::FETCH_OBJ ]) : mixed
Parameters
$fetch_parameters : int = PDO::FETCH_OBJ

The PDO fetch style record options

Return values
mixed —

The next row or false if we reached the end

fetchAll()

Fetches all rows from a result set and return them according to the $fetch_parameters format

public fetchAll([int $fetch_parameters = PDO::FETCH_OBJ ]) : mixed
Parameters
$fetch_parameters : int = PDO::FETCH_OBJ

The PDO fetch style record options

Return values
mixed —

The rows according to PDO fetch style or false if no record

getCurrentNumberOfRecords()

Returns the current number of records.

public getCurrentNumberOfRecords() : int
Return values
int —

The current number of records.

getCurrentPage()

Retrieves the current page number.

public getCurrentPage() : int
Return values
int —

The current page number.

getDb()

Get the database instance.

public getDb() : Db
Return values
Db —

The database instance.

getNumberOfPages()

Returns the number of pages.

public getNumberOfPages() : int
Return values
int —

The number of pages.

getRecordsPerPage()

Get the number of records to display per page.

public getRecordsPerPage() : int
Return values
int —

The number of records per page.

getTotalRecordsCount()

Returns the total number of records in the dataset.

public getTotalRecordsCount() : int
Return values
int —

The total number of records.

pagine()

Build pagination

public pagine(string $url) : string
Parameters
$url : string

The base URL for the pagination links.

Return values
string —

The HTML for the pagination links.

select()

Selects data from the database.

public select(string $from, string|array<string|int, string> $fields[, array<int|string, mixed>|string $where = [] ][, array<string, bool|int|string> $parameters = [] ][, bool|string $debug = false ]) : self
Parameters
$from : string

The SQL FROM statement with optional joins. Example: 'table1 INNER JOIN table2 ON table1.id = table2.id'.

$fields : string|array<string|int, string>

The columns to select. Can be a string or an array of strings.

$where : array<int|string, mixed>|string = []

The WHERE clause. Can be a string or an array of conditions. If it's an array, the conditions will be joined with AND.

$parameters : array<string, bool|int|string> = []

An associative array of parameter names and values.

$debug : bool|string = false

false, true or silent. false: the production mode. true: The query is displayed. 'silent': The query is registered then can be displayed using the getDebug() method.

Return values
self

setCurrentPage()

Sets the current page number and overrides the querystring.

public setCurrentPage(int $currentPage) : void
Parameters
$currentPage : int

The current page number.

setOptions()

Sets the options for pagination.

public setOptions(array<string, bool|string> $options) : void
Parameters
$options : array<string, bool|string>

An array of options for pagination.

setRecordsPerPage()

Sets the number of records to display per page.

public setRecordsPerPage(int $recordsPerPage) : self
Parameters
$recordsPerPage : int

The number of records to display per page.

Return values
self

removePreviousQuerystring()

Removes any previous querystring parameters from the URL.

private removePreviousQuerystring(string $url) : string
Parameters
$url : string

The URL to remove the querystring from

Return values
string —

The updated URL


        
On this page

Search results