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

Named params in routing

I have one action mapped to two routes. Action look like this:

public function indexAction($salon=null,$page=null)
{
}

And routes like this, its route group witch is mounted later:

$this->addGet('/index/{salon:[0-9]+$}', array('action'=>'index','controller'=>'department'));
$this->addGet('/page/{page:[0-9]+$}', array('action'=>'index','controller'=>'department'));

But when i acess /page/1 the page is stored in $salon, is that how it should work ?



51.2k

Yes, this is how it should work. You should rewrite it:

$this->addGet('/page/{salon:[0-9]+$}/{page:[0-9]+$}', array('action'=>'index','controller'=>'department'));

Or just forget about method params and use

public function indexAction()
{
    $salon = $this->dispatcher->getParam('salon');
}

You can visualize all params:

    var_dump($this->dispatcher->getParams(););