0

I'm trying to make pagination for a listing page, and I'm having problems setting default value for $page with getParam method from dispatcher.

The URL is like this : (http://www.example.com/category/subcategory/page_number_here)

This is how I get page param from dispatcher

$page = $this->dispatcher->getParam('page', 'int', 1);

the problem is that when I put letters only (or nothing at all) for page, it doesn't set $page with 1 as I expect it to do, it sets it with an empty string.

Am I doing something wrong, is there something that I got it wrong on how it should work?

Thanks.

1 Answers1

1

Param methods in dispatcher will work only if you have named parameters defined in your routing definitions, what may happen to be a bit tricky.

I would recommend you to use request service:

$this->request->get('page', 'int', 1)

For this to work you will also be required to tweak your routing definitions because at this point Phalcon does not know where page param exists, but may be it will be a bit less complicated. You will find it out what approach suits you better.

yergo
  • 4,761
  • 2
  • 19
  • 41