We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Pagination in PHQL query

Hi, I need to use PHQL query, but I also want to use pagination.

example

$phql = "SELECT p.*  FROM Models\Products AS p ";
$products = \Phalcon\DI::getDefault()->get('modelsManager')->createQuery($phql);

doesn't work like that

$paginator = new Phalcon\Paginator\Adapter\QueryBuilder (
            [
                'builder' => $productsData,
                'limit'   => $limit,
                'page'    => $page,
            ]
        );

Is it possible? any thoughts?

AFAIK this:

$products = \Phalcon\DI::getDefault()->get('modelsManager')->createQuery($phql);

is creating object of Query class not QueryBuilder class which is needed by Paginator, You need to execute createBuilder method on modelsManager.

edited Dec '19

I just used a query using createBuilder(). But now I need an analog pagination for createQuery(). therefore I ask whether this is possible?

AFAIK this:

$products = \Phalcon\DI::getDefault()->get('modelsManager')->createQuery($phql);

is creating object of Query class not QueryBuilder class which is needed by Paginator, You need to execute createBuilder method on modelsManager.