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

How to set routing for dynamic GET Parameters

Hi Guys,

I am using Phalcon Paginator. Instead of

/products/list/?page=1

i would like to have

/products/list/1

How do i do this using routing? This is what i come of with, but does not work.

    $router->add('/products/list/:params', array(
    'controller' => 'products',
    'action'     => 'list',
    "params"     => $_GET['page']
));  

Advice appreciated!



4.0k
Accepted
answer

Try:

$router->add('/products/list/{page:[0-9]+}', array(
    'controller' => 'products',
    'action'     => 'list'
));
class ProductsControler ...
{
    public function listAction($page = null)
    {

    }
}