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

Routing to only path specified

Hello! I'm trying to setup route which will runs on only specified path. $router->add(':controller/(v1|v2)/:action/', array('controller' =>1, 'action' =>3, 'param' => 2))

I need that action should be executed only for v1 or v2 path, but it executes even for other actions. What I'm doing wrong?

Another example: $accountGroup->add('/show/:int', array( 'action' => 'show', 'id' => 1 )); Calling url: localhost/account/show/randomstring (account is set as prefix and controller for Router\Group) will lead to execute showAction() even if we pass non-int params



98.9k

It seems you're missing the leading slash:

$router->add('/:controller/(v1|v2)/:action/', array('controller' =>1, 'action' =>3, 'param' => 2))