GitHub Project

layout: default language: 'zh-cn' version: '4.0' title: 'Phalcon\Paginator'

Abstract Class Phalcon\Paginator\Adapter\AbstractAdapter

Source on GitHub

| Namespace | Phalcon\Paginator\Adapter | | Uses | Phalcon\Paginator\Exception, Phalcon\Paginator\Repository, Phalcon\Paginator\RepositoryInterface | | Implements | AdapterInterface |

Phalcon\Paginator\Adapter\AbstractAdapter

Properties

/**
 * Configuration of paginator
 */
protected config;

/**
 * Number of rows to show in the paginator. By default is null
 */
protected limitRows;

/**
 * Current page in paginate
 */
protected page;

/**
 * Repository for pagination
 *
 * @var RepositoryInterface
 */
protected repository;

Methods

public function __construct( array $config );

Phalcon\Paginator\Adapter\AbstractAdapter constructor

public function getLimit(): int;

Get current rows limit

public function setCurrentPage( int $page ): AdapterInterface;

Set the current page number

public function setLimit( int $limitRows ): AdapterInterface;

Set current rows limit

public function setRepository( RepositoryInterface $repository ): AdapterInterface;

Sets current repository for pagination

protected function getRepository( array $properties = null ): RepositoryInterface;

Gets current repository for pagination

Interface Phalcon\Paginator\Adapter\AdapterInterface

Source on GitHub

| Namespace | Phalcon\Paginator\Adapter | | Uses | Phalcon\Paginator\RepositoryInterface |

Phalcon\Paginator\AdapterInterface

Interface for Phalcon\Paginator adapters

Methods

public function getLimit(): int;

Get current rows limit

public function paginate(): RepositoryInterface;

Returns a slice of the resultset to show in the pagination

public function setCurrentPage( int $page );

Set the current page number

public function setLimit( int $limit );

Set current rows limit

Class Phalcon\Paginator\Adapter\Model

Source on GitHub

| Namespace | Phalcon\Paginator\Adapter | | Uses | Phalcon\Helper\Arr, Phalcon\Mvc\ModelInterface, Phalcon\Mvc\Model\ResultsetInterface, Phalcon\Paginator\Exception, Phalcon\Paginator\RepositoryInterface | | Extends | AbstractAdapter |

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();

Methods

public function paginate(): RepositoryInterface;

Returns a slice of the resultset to show in the pagination

Class Phalcon\Paginator\Adapter\NativeArray

Source on GitHub

| Namespace | Phalcon\Paginator\Adapter | | Uses | Phalcon\Paginator\Exception, Phalcon\Paginator\RepositoryInterface | | Extends | AbstractAdapter |

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,
    ]
);

Methods

public function paginate(): RepositoryInterface;

Returns a slice of the resultset to show in the pagination

Class Phalcon\Paginator\Adapter\QueryBuilder

Source on GitHub

| Namespace | Phalcon\Paginator\Adapter | | Uses | Phalcon\Db\Enum, Phalcon\Mvc\Model\Query\Builder, Phalcon\Paginator\RepositoryInterface, Phalcon\Paginator\Exception | | Extends | AbstractAdapter |

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,
    ]
);

Properties

/**
 * Paginator's data
 */
protected builder;

/**
 * Columns for count query if builder has having
 */
protected columns;

Methods

public function __construct( array $config );

Phalcon\Paginator\Adapter\QueryBuilder

public function getCurrentPage(): int;

Get the current page number

public function getQueryBuilder(): Builder;

Get query builder object

public function paginate(): RepositoryInterface;

Returns a slice of the resultset to show in the pagination

public function setQueryBuilder( Builder $builder ): QueryBuilder;

Set query builder object

Class Phalcon\Paginator\Exception

Source on GitHub

| Namespace | Phalcon\Paginator | | Extends | \Phalcon\Exception |

Phalcon\Paginator\Exception

Exceptions thrown in Phalcon\Paginator will use this class

Class Phalcon\Paginator\PaginatorFactory

Source on GitHub

| Namespace | Phalcon\Paginator | | Uses | Phalcon\Paginator\Adapter\AdapterInterface, Phalcon\Factory\AbstractFactory, Phalcon\Helper\Arr | | Extends | AbstractFactory |

This file is part of the Phalcon Framework.

(c) Phalcon Team team@phalcon.io

For the full copyright and license information, please view the LICENSE.txt file that was distributed with this source code.

Methods

public function __construct( array $services = [] );

AdapterFactory constructor.

public function load( mixed $config ): AdapterInterface;

Factory to create an instace 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);
public function newInstance( string $name, array $options = [] ): AdapterInterface;

Create a new instance of the adapter

protected function getAdapters(): array;

//

Class Phalcon\Paginator\Repository

Source on GitHub

| Namespace | Phalcon\Paginator | | Uses | JsonSerializable, Phalcon\Helper\Arr | | Implements | RepositoryInterface, JsonSerializable |

Phalcon\Paginator\Repository

Repository of current state Phalcon\Paginator\AdapterInterface::paginate()

Properties

/**
 * @var array
 */
protected aliases;

/**
 * @var array
 */
protected properties;

Methods

public function __get( string $property ): mixed | null;

{@inheritdoc}

public function getAliases(): array;

{@inheritdoc}

public function getCurrent(): int;

{@inheritdoc}

public function getFirst(): int;

{@inheritdoc}

public function getItems(): mixed;

{@inheritdoc}

public function getLast(): int;

{@inheritdoc}

public function getLimit(): int;

{@inheritdoc}

public function getNext(): int;

{@inheritdoc}

public function getPrevious(): int;

{@inheritdoc}

public function getTotalItems(): int;

{@inheritdoc}

public function jsonSerialize(): array;

See jsonSerialize

public function setAliases( array $aliases ): RepositoryInterface;

{@inheritdoc}

public function setProperties( array $properties ): RepositoryInterface;

{@inheritdoc}

protected function getProperty( string $property, mixed $defaultValue = null ): mixed;

Gets value of property by name

protected function getRealNameProperty( string $property ): string;

Resolve alias property name

Interface Phalcon\Paginator\RepositoryInterface

Source on GitHub

| Namespace | Phalcon\Paginator |

Phalcon\Paginator\RepositoryInterface

Interface for the repository of current state Phalcon\Paginator\AdapterInterface::paginate()

常量

const PROPERTY_CURRENT_PAGE = current;
const PROPERTY_FIRST_PAGE = first;
const PROPERTY_ITEMS = items;
const PROPERTY_LAST_PAGE = last;
const PROPERTY_LIMIT = limit;
const PROPERTY_NEXT_PAGE = next;
const PROPERTY_PREVIOUS_PAGE = previous;
const PROPERTY_TOTAL_ITEMS = total_items;

Methods

public function getAliases(): array;

Gets the aliases for properties repository

public function getCurrent(): int;

Gets number of the current page

public function getFirst(): int;

Gets number of the first page

public function getItems(): mixed;

Gets the items on the current page

public function getLast(): int;

Gets number of the last page

public function getLimit(): int;

Gets current rows limit

public function getNext(): int;

Gets number of the next page

public function getPrevious(): int;

Gets number of the previous page

public function getTotalItems(): int;

Gets the total number of items

public function setAliases( array $aliases ): RepositoryInterface;

Sets the aliases for properties repository

public function setProperties( array $properties ): RepositoryInterface;

Sets values for properties of the repository