Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

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

http://example.org/forum/1234

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



83.4k
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
));


610

oh yeah~ successful !!