Skip to content

Paginator ​

Type
Class
Namespace
craft\db
Inherits
craft\db\Paginator » yii\base\BaseObject
Implements
yii\base\Configurable
Since
3.1.19

Query Paginator


php
use craft\db\Paginator;

$paginator = new Paginator($query, [
    'pageSize' => 10,
    'currentPage' => \Craft::$app->request->pageNum,
]);

$pageResults = $paginator->getPageResults();
twig
{% set paginator = create('craft\\db\\Paginator', [query, {
  pageSize: 10,
  currentPage: craft.app.request.pageNum,
}]) %}

{% set pageResults = paginator.getPageResults() %}

View source

Public Properties ​

PropertyDescription
dbyii\db\Connection, array, string, null – The DB connection to be used with the query.
pageOffsetinteger, float
pageResultsarray
pageSizeinteger – The number of results to include for each page

db ​

Type
yii\db\Connection, array, string, null
Default value
null

The DB connection to be used with the query. If null, the query will choose the connection to use.

View source

pageOffset ​

Type
integer, float
Default value
null
Access
Read-only

View source

pageResults ​

Type
array
Default value
null

View source

pageSize ​

Type
integer
Default value
100

The number of results to include for each page

View source

Protected Properties ​

PropertyDescription
currentPageinteger – The current page
queryyii\db\QueryInterface – The query being paginated
totalPagesinteger – The total number of pages
totalResultsinteger – The total query count

currentPage ​

Type
integer
Default value
1

The current page

View source

query ​

Type
yii\db\QueryInterface
Default value
null

The query being paginated

View source

totalPages ​

Type
integer
Default value
null

The total number of pages

View source

totalResults ​

Type
integer
Default value
null

The total query count

View source

Public Methods ​

MethodDescription
__call()Calls the named method which is not a class method.
__construct()Constructor
__get()Returns the value of an object property.
__isset()Checks if a property is set, i.e. defined and not null.
__set()Sets value of an object property.
__unset()Sets an object property to null.
canGetProperty()Returns a value indicating whether a property can be read.
canSetProperty()Returns a value indicating whether a property can be set.
className()Returns the fully qualified name of this class.
getCurrentPage()Returns the current page
getPageOffset()Returns the offset of the first result returned by getPageResults()
getPageResults()Returns the results for the current page
getTotalPages()Returns the total number of pages
getTotalResults()Returns the total number of query results
hasMethod()Returns a value indicating whether a method is defined.
hasProperty()Returns a value indicating whether a property is defined.
init()Initializes the object.
setCurrentPage()Sets the current page
setPageResults()Sets the results for the current page.

__construct() ​

Constructor

View source

Arguments ​

getCurrentPage() ​

Returns the current page

View source

Returns ​

integer

getPageOffset() ​

Returns the offset of the first result returned by getPageResults()

View source

Returns ​

integer, float

getPageResults() ​

Returns the results for the current page

View source

Returns ​

array

getTotalPages() ​

Returns the total number of pages

View source

Returns ​

integer

getTotalResults() ​

Returns the total number of query results

View source

Returns ​

integer, float

init() ​

Initializes the object.

This method is invoked at the end of the constructor after the object is initialized with the given configuration.

View source

Throws ​

setCurrentPage() ​

Sets the current page

View source

Arguments ​

setPageResults() ​

Since
3.1.22

Sets the results for the current page.

View source

Arguments ​