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

ODM pagination

I'm rolling my own pagination for my models.

What is the preferred way to get the total count when making a limited, skipped find()?

Getting the whole result and then just taking the required objects seems wasteful, especially when I only need the first 20 of 10,000 records.

Thanks



8.7k

Figured this out myself.

Made this method on my Collection:

public static function countQuery($arr) {
    $coll = new self();
    return self::_getGroupResultset($arr, $coll, $coll->getConnection());
}

I call this to get my total count then add the limit and skip parameters to my query for the results I need.



21.7k

Hi, Ty Kroll!

What's usecase for that?