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

optional route parameters

Hi. How can I have optional parameters in a route?

for example in Laravel 4, I could do this:

Route::get('/somewhere/{param1?}, [ 'use' => '[email protected]' ] );

The Param1 is optional in above route. so User can navigate to

https://www.example.com/somewhere/xyz

AND

https://www.example.com/somewhere

How can I do that in phalconphp?

Problem with params: is that the parameter has to be named in the URL like example.com/customer/address/id/123 instead of using example.com/customer/address/123 without breaking example.com/customer/address.

Possible solution: https://forum.phalcon.io/discussion/626/mvc-route-with-optional-param-problem-with-generating-correct-ro#C24369