We are moving our forum in GitHub Discussions. For questions about Phalcon v3/v4 you can visit here and for Phalcon v5 here.

Routing - making route segments optional

Hi all,

I have posted this question on StackOverflow:


Any help will be appreciated. It's unclear from the docs how one would make route segments optional. I did not have the same problem with Zend Framework routes, so assumed Phalcon would do something similar

Thank you, Temuri



Thanks. But that suggestion seems to be more of a workaround and does not work as I expect.

I've defined route as: /admin[/]?{controller:[a-z]}[/]?{action:[a-z]}

That matched /admin/foo/bar just fine.

However, /admin/foo populated 'controller' with 'foo' and 'action' was an empty string (not a default 'index').

I've looked around some more and it does seem to be possible to have segments optional.

It's a pity, as that significantly increases number of routes I have to define.