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() %}Public Properties ​
| Property | Description |
|---|---|
| db | yii\db\Connection, array, class-string<\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, array,
class-string<\yii\db\Connection>, null - Default value
null
The DB connection to be used with the query. If null, the query will choose the connection to use.
pageOffset ​
pageResults ​
- Type
- array
- Default value
null
pageSize ​
- Type
- integer
- Default value
100
The number of results to include for each page
Protected Properties ​
| Property | Description |
|---|---|
| currentPage | integer – The current page |
| query | yii\db\QueryInterface – The query being paginated |
| totalPages | integer – The total number of pages |
| totalResults | integer – The total query count |
currentPage ​
- Type
- integer
- Default value
1
The current page
query ​
- Type
- yii\db\QueryInterface
- Default value
null
The query being paginated
totalPages ​
- Type
- integer
- Default value
null
The total number of pages
totalResults ​
- Type
- integer
- Default value
null
The total query count
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
Arguments ​
$query(yii\db\QueryInterface) – The query that should be paginated$config(array)
getCurrentPage() ​
Returns the current page
Returns ​
getPageOffset() ​
Returns the offset of the first result returned by getPageResults()
Returns ​
getPageResults() ​
Returns the results for the current page
Returns ​
getTotalPages() ​
Returns the total number of pages
Returns ​
getTotalResults() ​
Returns the total number of query results
Returns ​
init() ​
Initializes the object.
This method is invoked at the end of the constructor after the object is initialized with the given configuration.
Throws ​
setCurrentPage() ​
Sets the current page
Arguments ​
$currentPage(integer)
setPageResults() ​
- Since
- 3.1.22
Sets the results for the current page.
Arguments ​
$pageResults(array)