We are moving our forum in GitHub Discussions. For questions about Phalcon v3/v4 you can visit here and for Phalcon v5 here.

Can't loop through pagination


I've run into a pagination issue that I can't resolve. It's permanently stuck at the first 4 items as defined in paginator limit, or page one. Page two shows the same records and won't let me go any further than that with the next button. Is there something wrong with my code?

In my TestController.php I have the following:

    public function indexAction()
        $numberPage = 1;

        $items = Items::find();

        $paginator = new Paginator([
            "data"  => $items,
            "limit" => 4,
            "page"  => $numberPage,

        $this->view->title = 'Test Index';
        $this->view->items = $items;
        $this->view->page  = $paginator->getPaginate();


And in the corresonding volt view I have:

{% for item in page.items %}
    {{ item.title }}
{% endfor %}

// further down

<li>{{ link_to("test", 'First') }}</li>
<li>{{ link_to("test?page=" ~ page.before, '&larr; Previous') }}</li>
<li>{{ link_to("test?page=" ~ page.next, 'Next &rarr;') }}</li>
<li>{{ link_to("test?page=" ~ page.last, 'Last') }}</li>

Thank you

edited Sep '17

You have $numberPage = 1. So how you expect to have other page? You don't access page from query, you need to do something like:

$numberPage = $this->request->getQuery('page', 'int', 1)



Right, thank you. I was just following the docs and that's how it was written. I'm lerning both PHP and Phalcon at the same time so I'm kinda ignorant.