Phalcon paginator
NOTE
All classes are prefixed with Phalcon
Paginator\Adapter\AbstractAdapter¶
Abstract Source on GitHub
Phalcon\Paginator\Adapter\AbstractAdapter
Phalcon\Paginator\Adapter\AbstractAdapter- implementsPhalcon\Paginator\Adapter\AdapterInterface
Uses Phalcon\Paginator\Exception · Phalcon\Paginator\Exceptions\InvalidLimit · Phalcon\Paginator\Exceptions\MissingRequiredParameter · Phalcon\Paginator\Repository · Phalcon\Paginator\RepositoryInterface
Method Summary¶
public
__construct( array $config )
Phalcon\Paginator\Adapter\AbstractAdapter constructor
public
int
getLimit()
Get current rows limit
public
AdapterInterface
setCurrentPage( int $page )
Set the current page number
public
AdapterInterface
setLimit( int $limit )
Set current rows limit
public
AdapterInterface
setRepository( RepositoryInterface $repository )
Sets current repository for pagination
protected
RepositoryInterface
getRepository( array $properties = null )
Gets current repository for pagination
Properties¶
protected
array
$config
Configuration of paginator
protected
int|null
$limitRows = null
Number of rows to show in the paginator. By default is null
protected
int|null
$page = null
Current page in paginate
protected
RepositoryInterface
$repository
Repository for pagination
Methods¶
__construct()¶
Phalcon\Paginator\Adapter\AbstractAdapter constructor
getLimit()¶
Get current rows limit
setCurrentPage()¶
Set the current page number
setLimit()¶
Set current rows limit
setRepository()¶
Sets current repository for pagination
getRepository()¶
Gets current repository for pagination
Paginator\Adapter\AdapterInterface¶
Interface Source on GitHub
Phalcon\Contracts\Paginator\AdapterPhalcon\Paginator\Adapter\AdapterInterface
Uses Phalcon\Contracts\Paginator\Adapter
Paginator\Adapter\Model¶
Class Source on GitHub
Phalcon\Paginator\Adapter\Model
This adapter allows to paginate data using a Phalcon\Mvc\Model resultset as a base.
use Phalcon\Paginator\Adapter\Model;
$paginator = new Model(
[
"model" => Robots::class,
"limit" => 25,
"page" => $currentPage,
]
);
$paginator = new Model(
[
"model" => Robots::class,
"parameters" => [
"columns" => "id, name"
],
"limit" => 12,
"page" => $currentPage,
]
);
$paginator = new Model(
[
"model" => Robots::class,
"parameters" => [
"type = :type:",
"bind" => [
"type" => "mechanical"
],
"order" => "name"
],
"limit" => 16,
"page" => $currentPage,
]
);
$paginator = new Model(
[
"model" => Robots::class,
"parameters" => "(id % 2) = 0",
"limit" => 8,
"page" => $currentPage,
]
);
$paginator = new Model(
[
"model" => Robots::class,
"parameters" => [ "(id % 2) = 0" ],
"limit" => 8,
"page" => $currentPage,
]
);
$paginate = $paginator->paginate();
Phalcon\Paginator\Adapter\AbstractAdapterPhalcon\Paginator\Adapter\Model
Uses Phalcon\Mvc\ModelInterface · Phalcon\Mvc\Model\ResultsetInterface · Phalcon\Paginator\Exception · Phalcon\Paginator\Exceptions\MissingRequiredParameter · Phalcon\Paginator\RepositoryInterface
Method Summary¶
public
__construct( array $config )
Phalcon\Paginator\Adapter\Model constructor
public
RepositoryInterface
paginate()
Returns a slice of the resultset to show in the pagination
Methods¶
__construct()¶
Phalcon\Paginator\Adapter\Model constructor
paginate()¶
Returns a slice of the resultset to show in the pagination
Paginator\Adapter\NativeArray¶
Class Source on GitHub
Phalcon\Paginator\Adapter\NativeArray
Pagination using a PHP array as source of data
use Phalcon\Paginator\Adapter\NativeArray;
$paginator = new NativeArray(
[
"data" => [
["id" => 1, "name" => "Artichoke"],
["id" => 2, "name" => "Carrots"],
["id" => 3, "name" => "Beet"],
["id" => 4, "name" => "Lettuce"],
["id" => 5, "name" => ""],
],
"limit" => 2,
"page" => $currentPage,
]
);
Phalcon\Paginator\Adapter\AbstractAdapterPhalcon\Paginator\Adapter\NativeArray
Uses Phalcon\Paginator\Exception · Phalcon\Paginator\Exceptions\PaginatorDataNotArray · Phalcon\Paginator\RepositoryInterface
Method Summary¶
Methods¶
paginate()¶
Returns a slice of the resultset to show in the pagination
Paginator\Adapter\QueryBuilder¶
Class Source on GitHub
Phalcon\Paginator\Adapter\QueryBuilder
Pagination using a PHQL query builder as source of data
use Phalcon\Paginator\Adapter\QueryBuilder;
$builder = $this->modelsManager->createBuilder()
->columns("id, name")
->from(Robots::class)
->orderBy("name");
$paginator = new QueryBuilder(
[
"builder" => $builder,
"limit" => 20,
"page" => 1,
]
);
Phalcon\Paginator\Adapter\AbstractAdapterPhalcon\Paginator\Adapter\QueryBuilder
Uses Phalcon\Db\Enum · Phalcon\Mvc\Model\Query\Builder · Phalcon\Paginator\Exception · Phalcon\Paginator\Exceptions\BuilderModelNotDefined · Phalcon\Paginator\Exceptions\InvalidBuilderInstance · Phalcon\Paginator\Exceptions\MissingColumnsForHaving · Phalcon\Paginator\Exceptions\MissingRequiredParameter · Phalcon\Paginator\RepositoryInterface
Method Summary¶
public
__construct( array $config )
Phalcon\Paginator\Adapter\QueryBuilder
public
int
getCurrentPage()
Get the current page number
public
Builder
getQueryBuilder()
Get query builder object
public
RepositoryInterface
paginate()
Returns a slice of the resultset to show in the pagination
public
static
setQueryBuilder( Builder $builder )
Set query builder object
Properties¶
protected
Builder
$builder
Paginator's data
protected
array|string
$columns
Column list used only for COUNT rewriting when the builder carries a
HAVING or GROUP BY clause. It supplies the columns for the subquery
that counts the grouped/having result set and is ignored otherwise.
Methods¶
__construct()¶
Phalcon\Paginator\Adapter\QueryBuilder
The columns option is not a projection for the paginated rows; it is
consumed solely by the total-count rewrite when the builder has a
HAVING or GROUP BY clause (it becomes the column list of the counting
subquery). It has no effect on plain queries.
getCurrentPage()¶
Get the current page number
getQueryBuilder()¶
Get query builder object
paginate()¶
Returns a slice of the resultset to show in the pagination
setQueryBuilder()¶
Set query builder object
Paginator\Adapter\QueryBuilderCursor¶
Class Source on GitHub
Phalcon\Paginator\Adapter\QueryBuilderCursor
Cursor-based (keyset) pagination using a PHQL query builder as source of data.
Unlike offset pagination, this adapter does not use an ever-growing OFFSET. It appends a WHERE condition on a unique, indexed cursor column so that each page is an O(1) index seek regardless of depth.
Limitations:
- No total count: getTotalItems() always returns 0.
- No random access: getLast() always returns 0. Pages must be traversed
in order by following the cursor value returned in getNext().
- The cursor column must be unique and indexed (e.g. a primary key).
- Items are returned as an array of associative arrays (via
Resultset::toArray()), not as model objects.
- cursorColumn must match the PHQL-accessible column name exactly
(e.g. "inv_id").
use Phalcon\Paginator\Adapter\QueryBuilderCursor;
$builder = $this->modelsManager->createBuilder()
->columns("inv_id, inv_title")
->from(Invoices::class)
->orderBy("inv_id");
$paginator = new QueryBuilderCursor(
[
"builder" => $builder,
"limit" => 20,
"cursorColumn" => "inv_id",
"cursor" => null, // first page; pass $page->getNext() for subsequent pages
]
);
$page = $paginator->paginate();
// $page->getItems() - array of rows for this page
// $page->getNext() - cursor value to pass for the next page (0 means no more pages)
// $page->getCurrent() - cursor value used for this page (0 on first page)
Phalcon\Paginator\Adapter\AbstractAdapterPhalcon\Paginator\Adapter\QueryBuilderCursor
Uses Phalcon\Mvc\Model\Query\Builder · Phalcon\Paginator\Exception · Phalcon\Paginator\Exceptions\InvalidBuilderInstance · Phalcon\Paginator\Exceptions\InvalidCursorColumn · Phalcon\Paginator\Exceptions\MissingRequiredParameter · Phalcon\Paginator\RepositoryInterface
Method Summary¶
public
__construct( array $config )
Phalcon\Paginator\Adapter\QueryBuilderCursor
public
int
getCurrentPage()
Get the current page number
public
mixed
getCursor()
Get the cursor value for the current page (null on first page)
public
string
getCursorColumn()
Get the cursor column name
public
Builder
getQueryBuilder()
Get query builder object
public
RepositoryInterface
paginate()
Returns a slice of the resultset to show in the pagination
public
static
setCursor( mixed $cursor )
Set the cursor value for the next paginate() call
public
static
setQueryBuilder( Builder $builder )
Set query builder object
Properties¶
protected
Builder
$builder
Paginator's data
protected
mixed
$cursor = null
The cursor value for the current page (null = first page)
protected
string
$cursorColumn
The column used as the cursor (must be unique and indexed)
Methods¶
__construct()¶
Phalcon\Paginator\Adapter\QueryBuilderCursor
getCurrentPage()¶
Get the current page number
Returns the cursor value used for this page cast to int, or 0 for the first page. Use getCursor() to retrieve the raw cursor value.
getCursor()¶
Get the cursor value for the current page (null on first page)
getCursorColumn()¶
Get the cursor column name
getQueryBuilder()¶
Get query builder object
paginate()¶
Returns a slice of the resultset to show in the pagination
Fetches limit + 1 rows from the builder. If the extra row is present
a next page exists; it is discarded and the cursor value of the last
included row is stored in the next repository property.
setCursor()¶
Set the cursor value for the next paginate() call
Pass the value returned by Repository::getNext() to advance to the next page, or null to restart from the first page.
setQueryBuilder()¶
Set query builder object
Paginator\Exception¶
Class Source on GitHub
Phalcon\Paginator\Exception
Exceptions thrown in Phalcon\Paginator will use this class
\ExceptionPhalcon\Paginator\ExceptionPhalcon\Paginator\Exceptions\BuilderModelNotDefinedPhalcon\Paginator\Exceptions\InvalidBuilderInstancePhalcon\Paginator\Exceptions\InvalidCursorColumnPhalcon\Paginator\Exceptions\InvalidLimitPhalcon\Paginator\Exceptions\MissingColumnsForHavingPhalcon\Paginator\Exceptions\MissingRequiredParameterPhalcon\Paginator\Exceptions\PaginatorDataNotArray
Paginator\Exceptions\BuilderModelNotDefined¶
Class Source on GitHub
\ExceptionPhalcon\Paginator\ExceptionPhalcon\Paginator\Exceptions\BuilderModelNotDefined
Uses Phalcon\Paginator\Exception
Method Summary¶
Methods¶
__construct()¶
Paginator\Exceptions\InvalidBuilderInstance¶
Class Source on GitHub
\ExceptionPhalcon\Paginator\ExceptionPhalcon\Paginator\Exceptions\InvalidBuilderInstance
Uses Phalcon\Paginator\Exception
Method Summary¶
Methods¶
__construct()¶
Paginator\Exceptions\InvalidCursorColumn¶
Class Source on GitHub
\ExceptionPhalcon\Paginator\ExceptionPhalcon\Paginator\Exceptions\InvalidCursorColumn
Uses Phalcon\Paginator\Exception
Method Summary¶
Methods¶
__construct()¶
Paginator\Exceptions\InvalidLimit¶
Class Source on GitHub
\ExceptionPhalcon\Paginator\ExceptionPhalcon\Paginator\Exceptions\InvalidLimit
Uses Phalcon\Paginator\Exception
Method Summary¶
Methods¶
__construct()¶
Paginator\Exceptions\MissingColumnsForHaving¶
Class Source on GitHub
\ExceptionPhalcon\Paginator\ExceptionPhalcon\Paginator\Exceptions\MissingColumnsForHaving
Uses Phalcon\Paginator\Exception
Method Summary¶
Methods¶
__construct()¶
Paginator\Exceptions\MissingRequiredParameter¶
Class Source on GitHub
\ExceptionPhalcon\Paginator\ExceptionPhalcon\Paginator\Exceptions\MissingRequiredParameter
Uses Phalcon\Paginator\Exception
Method Summary¶
Methods¶
__construct()¶
getParameter()¶
Paginator\Exceptions\PaginatorDataNotArray¶
Class Source on GitHub
\ExceptionPhalcon\Paginator\ExceptionPhalcon\Paginator\Exceptions\PaginatorDataNotArray
Uses Phalcon\Paginator\Exception
Method Summary¶
Methods¶
__construct()¶
Paginator\PaginatorFactory¶
Class Source on GitHub
Phalcon\Factory\AbstractConfigFactoryPhalcon\Factory\AbstractFactoryPhalcon\Paginator\PaginatorFactory
Uses Phalcon\Factory\AbstractFactory · Phalcon\Paginator\Adapter\AdapterInterface
Method Summary¶
public
__construct( array $services = [] )
AdapterFactory constructor.
public
AdapterInterface
load( mixed $config )
Factory to create an instance from a Config object
public
AdapterInterface
newInstance(string $name,array $options = [])
Create a new instance of the adapter
protected
string
getExceptionClass()
protected
array
getServices()
Returns the available adapters
Methods¶
__construct()¶
AdapterFactory constructor.
load()¶
Factory to create an instance from a Config object
use Phalcon\Paginator\PaginatorFactory;
$builder = $this
->modelsManager
->createBuilder()
->columns("id, name")
->from(Robots::class)
->orderBy("name");
$options = [
"builder" => $builder,
"limit" => 20,
"page" => 1,
"adapter" => "queryBuilder",
];
$paginator = (new PaginatorFactory())->load($options);
newInstance()¶
Create a new instance of the adapter
getExceptionClass()¶
getServices()¶
Returns the available adapters
Paginator\Repository¶
Class Source on GitHub
Phalcon\Paginator\Repository
Repository of current state Phalcon\Paginator\AdapterInterface::paginate()
Phalcon\Paginator\Repository- implementsPhalcon\Paginator\RepositoryInterface,JsonSerializable
Uses JsonSerializable
Method Summary¶
public
mixed|null
__get( string $property )
{@inheritdoc}
public
array
getAliases()
{@inheritdoc}
public
int
getCurrent()
{@inheritdoc}
public
int
getFirst()
{@inheritdoc}
public
mixed
getItems()
{@inheritdoc}
public
int
getLast()
{@inheritdoc}
public
int
getLimit()
{@inheritdoc}
public
int
getNext()
{@inheritdoc}
public
int
getPrevious()
{@inheritdoc}
public
int
getTotalItems()
{@inheritdoc}
public
array
jsonSerialize()
See [jsonSerialize](https://php.net/manual/en/jsonserializable.jsonserialize.php)
public
RepositoryInterface
setAliases( array $aliases )
{@inheritdoc}
public
RepositoryInterface
setProperties( array $properties )
{@inheritdoc}
protected
mixed
getProperty(string $property,mixed $defaultValue = null)
Gets value of property by name
protected
string
getRealNameProperty( string $property )
Resolve alias property name
Properties¶
protected
array
$aliases = []
protected
array
$properties = []
Methods¶
__get()¶
{@inheritdoc}
getAliases()¶
{@inheritdoc}
getCurrent()¶
{@inheritdoc}
getFirst()¶
{@inheritdoc}
getItems()¶
{@inheritdoc}
getLast()¶
{@inheritdoc}
getLimit()¶
{@inheritdoc}
getNext()¶
{@inheritdoc}
getPrevious()¶
{@inheritdoc}
getTotalItems()¶
{@inheritdoc}
jsonSerialize()¶
See jsonSerialize
setAliases()¶
{@inheritdoc}
setProperties()¶
{@inheritdoc}
getProperty()¶
Gets value of property by name
getRealNameProperty()¶
Resolve alias property name
Paginator\RepositoryInterface¶
Interface Source on GitHub
Phalcon\Contracts\Paginator\RepositoryPhalcon\Paginator\RepositoryInterface
Uses Phalcon\Contracts\Paginator\Repository