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

Router: How to force matching rule to be last rule (stop looking after that)

I have following rules on my routing

$router->add('/profile/{name}', array( 'module' => 'frontend', 'namespace' => 'www\Frontend\Controllers\', 'controller' => 'profile', 'action' => 'view', "name" => 1, ));

This works fine, however i want to match following routes to differetn action how do i do that ?

$router->add('/profile/edit', array( 'module' => 'frontend', 'namespace' => 'xxx\Frontend\Controllers\', 'controller' => 'profile', 'action' => 'edit', "name" => 1, ));



125.8k
Accepted
answer

Since you can add many routes as you need using the add() method, the order in which routes are added indicate their relevance, latest routes added have more relevance than first added. Internally, all defined routes are traversed in reverse order until Phalcon\Mvc\Router finds the one that matches the given URI and processes it, while ignoring the rest.

I think this means if you put your /profile/edit rule below your generic /profile/{name} rule, then it will be encountered and routed first.