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 elements in route

Hi there,

I was looking at using Routes as I now have a need for some patterns that are a bit more adventurous than the default Route provided by Phalcon that handles controller/action/param.

Basically, I would like to define a route path where some of the parts are optional - for example, if I wanted to specify that 'param' (above) was optional. I couldn't find this capability specified in the Router docs, unless I missed it. Is it possible to define potentially captured named section(s) in a Route as optional?

Thanks.

Routes are just regex, so you should be able to define an optional section with +.

In my experience though, it's easier to just define 2 routes.



38.8k

Hi @quasipickle - many thanks for your thoughts around this.

Do you know if Phalcon uses different routes to cover its default routes? IOW, three routes for controller, controller/action and controller/action/param?

I don't know. It's probably more efficient to use 1 route.

Also, please don't use internet acronyms (ie: IOW), as not everyone knows them.



38.8k

Also, please don't use internet acronyms (ie: IOW), as not everyone knows them.

You can't be serious?

Actually he should be. I didn't know what IOW was until I googled it.

The point is that there are many people here whose primary language is not English. Not using acronyms helps :)



38.8k

We are on the internet, in an internet based community in 2014. On many multi-language forums, it's totally normal to see things like LOL, AFAIK, ROFLMAO, IOW, IIRC and so on. These kind of things generally transcend languages because they are so commonly used.

In terms of you having to Google "IOW", I guess that's the way of the world. I couldn't get through a single day at work, programming, without having to Google some issue or problem at least several times an hour.

I'll try and remember not to use acronyms in this forum in the future although I'd bet it's the very first time I used an acronym in any message I've posted and on the first occasion, I've been caught and summarily reprimanded <shrug>.

I'm surprised at the reaction but I'll take your word for it.

To be honest, I had to google what IOW meant too.

While to you and I might think LOL, or BRB are obvious, the truth is there are many people who aren't as versed in the acronyms as you or I might be. Using conversational English acronyms just makes it harder for others to read.

I'm sorry if my tone came off as a reprimand. It was merely intended as a friendly reminder that using acronyms would impede the usability of these forums for non-English speakers.



38.8k

I'm sorry if my tone came off as a reprimand. It was merely intended as a friendly reminder

No problem at all and thanks very much for clarifying your intentions. I personally appreciate your help and the help you give to others too :)

Regards.