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 with offset and limit

Hello everyone, I just start with Phalcon framework, passed trough documantacion and I like it so far... I have one fast question. Im building and api with phalcon and im stuck on part where I have to build pagination for pages. I have to make it with offset and limit parms. So GET /pages?limit=100&offset=100 would give the result set 101 - 200

So, should i make Controller method for pagination and use one of Phalcon ways with Adapter Model or Query Builder or there is a bether way .. btw im outputing json with transformer (dosent have views).

If I understand your question better use LIMIT in SQL. Because paginator of Phalcon did not know how to add LIMIT to the SQL query - it has been working with resulset of SQL query. It's not fast for many rows.



16.0k
Accepted
answer
edited Oct '15

Go for Query Builder since will only get what you need. Adapter Model will get all data at once and query through it

https://docs.phalcon.io/en/latest/reference/pagination.html#adapters-usage



23.6k

Thanks both on advice. I did it with Query Builder.