Hey there,
I'm writing an API app, complete with a versioning strategy. I found something really weird happening in the routing of modules. I posted originally at stack overflow (https://stackoverflow.com/questions/34170713/module-routing-not-right/34172068), but I didn't get an answer, so much as I got hacks (I mean no disrespect to the help I received; I greatly appreciate the help).
Here's the problem:
- /v1 | /v1/ - Doesn't work
- /v1/users | /v1/users/ - Works fine
- /v1/users/1 | /v1/users/1/ - Works fine
- /v1/users/1/permissions | /v1/users/1/permissions - Works fine
Here's the router itself:
$di->set('router', function () {
$router = new Router(false);
$router->setDefaultAction('index');
$router->setDefaultController('index');
$router->add('/:module/:controller/:params', array(
'module' => 1,
'controller' => 2,
'params' => 3
));
$router->removeExtraSlashes(true);
return $router;
});
At this point, I was hoping to get an explanation as to why this problem exists. I can't seem to figure out why the module doesn't match to the route. The rest of the routes work fine; it's just that first one that doesn't match. I am not looking for a solution; I wanted to get a converstaion going on why this is happening, and, if it's a potential problem, maybe talk about how we could fix it.
Any guidance would be great!
Thanks!