Paginator

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

Query Paginator

use craft\db\Paginator;

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

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

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

View source

# Public Properties

Property Description
db yii\db\Connection, null – The DB connection to be used with the query.
pageOffset integer, float
pageResults array
pageSize integer – The number of results to include for each page

# db

Type
yii\db\Connection, 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
Access
Read-only

View source

# pageResults

Type
array

View source

# pageSize

Type
integer

The number of results to include for each page

View source

# Protected Properties

Property Description
currentPage integer – The current page
query yii\db\QueryInterface, yii\db\Query – The query being paginated
totalPages integer – The total number of pages
totalResults integer – The total query count

# currentPage

Type
integer

The current page

View source

# query

Type
yii\db\QueryInterface, yii\db\Query

The query being paginated

View source

# totalPages

Type
integer

The total number of pages

View source

# totalResults

Type
integer

The total query count

View source

# Public Methods

Method Description
__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

  • $pageResults