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

controller, action name issue url

hi,

i got a bit of problem here. say if i have a controller name url = "item" without the proper controller file, i get an error 'itemController handler class cannot be loaded', which is correct. if the controller name url = "item-123" without the proper controller file, i get an error 'item123Controller handler class cannot be loaded', which is also correct.

but the same cannot be said with the action name url. if the controller/action name url = 'blog/show', without the controller with action file, error is "Action 'show' was not found on handler 'blog' which is correct. but if the action name contains any "-,+,:" etc, it doesn't show the error and the page goes to base/root url.

any ideas? thanks



98.9k

This happens because the routes by default don't allow certain characters so the route is not matched because the URI includes characters that aren't part of any route, you can set which characters must be allowed in the route:

$router = new Phalcon\Mvc\Router(false);

$router->add('/([a-zA-Z0-9\!\-\_]+)/([a-zA-Z0-9\!\-\_]+)(/.*)', array(
    'controller' => 1,
    'action' => 2,
    'params' => 3
));

$router->add('/([a-zA-Z0-9\!\-\_]+)', array(
    'controller' => 1,
));