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

custom routing not work correctly

I defined a route:

$di['router']->add('#^/([a-zA-Z0-9\_\-]+)/([0-9]+)#', array(
    'controller' => 1,
    'action' => 'index',
    'params' => 2
));

my controller

public function indexAction($id = 0)
{...}

my url

https://example.org/forum/1234

I expect that "1234" will be catched, but I catched "234". Why ?



98.9k
Accepted
answer

'params' is expected to being used alongside regular expressions that return an undefined list of parameters. You will not have this problem if you change it to:

$di['router']->add('#^/([a-zA-Z0-9\_\-]+)/([0-9]+)#', array(
    'controller' => 1,
    'action' => 'index',
    'parameters' => 2
));


1.0k

oh yeah~ successful !!