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 & URL generator

Guys,

In my opinion, routing and URL generation has been Phalcon's weakest spot. I'm saying weakest because it also happens to be one of the fundamental components.

I wasn't impressed when I first saw it about a year ago and it hasn't changed much since.

The biggest problem, in my opinion, is the lack of support for default parameters both when doing route matching and URL generation.

My question to the developers - do you guys plan some sort of functionality review or, possibly an entire overhaul of Router/URL generator? Or do you, instead think it is already OK the way it is?

Best wishes, Temuri



51.3k

In essence, here's my biggest problem with Phalcon route matching.

$di = new Phalcon\DI\FactoryDefault;
$router = $di['router'];

$router->add('/blog/:module/:controller/:action', [
    'module' => 1,
    'controller' => 2,
    'action' => 3,
])->setName('blog');

$url = $di['url'];
$url->setBaseUri('/offset/');

// THIS WORKS:
$router->handle('/blog/a/b/c');
$matchedRouteName = $router->getMatchedRoute()->getName(); // equals to 'blog'

// HOWEVER, I WOULD LIKE THIS TO WORK TOO:
$router->handle('/blog/a/b');
$matchedRouteName = $router->getMatchedRoute()->getName(); // is NULL

I would like to be able to define each segment of /:module/:controller/:action path as optional.

Maybe there's a practical reason it wasn't implemented that way?

Thanks!