freeway icon indicating copy to clipboard operation
freeway copied to clipboard

URL segment constraints

Open aboutwout opened this issue 14 years ago • 7 comments

Hi Doug,

Very nice extension and I can't wait to dig in (when I have a need for it), but there's one thing I'm missing compared to 'normal' routes in CI.

With CI routes you can do something like this:

`$route['product/(:num)'] = "catalog/product_lookup_by_id/$1";``

Which basically says that the 2nd segment has to be a number. Is there any way to incorporate this in Freeway?

– Wouter

aboutwout avatar Nov 08 '11 15:11 aboutwout

That's an excellent idea. Are there other params like that? :string, I'm guessing?

averyvery avatar Nov 08 '11 16:11 averyvery

:string would be a bit too broad I guess, since practically anything can be a string... I'd go with :alpha

You can read up on CI's routing options here

aboutwout avatar Nov 08 '11 16:11 aboutwout

Thanks, this is helpful. Will look through their routing system to get a better idea about how Freeway can work.

averyvery avatar Nov 08 '11 16:11 averyvery

I did a little bit of thinking and since you need a segment name to use for the {freeway_{name}} variables, you'd have to add the contraints to it.

Something like this:

product/{{product_id:num}}/{{action:alpha}}

Or even incorporate a regex pattern:

`product/{{product_id:(\d+)}}``

– Wouter

aboutwout avatar Nov 08 '11 16:11 aboutwout

Interesting. My original thought would be that if segments had restrictions or special parameters like that, they would look more like:

{{product_id only="num" match="^299.*?$" from="cat_id" to="cat_name"}}

Seems more idiomatic to EE, and provides more flexibility for future features.

averyvery avatar Nov 08 '11 17:11 averyvery

Adding this here because I think it also falls underneath URL segment constraints:

Currently the following route: /testroute => /

will match a URL of /testroute, but it will also match /testroute2. Possibly regex anchors could be used to specify the beginning and end of the route to be matched? In my mind my route would end up looking like:

^/testroute/$ => /

mildlygeeky avatar Nov 09 '11 03:11 mildlygeeky

Weird — thanks for catching that oversight. Will make sure to anchor the segments between ^ and $.

averyvery avatar Nov 09 '11 04:11 averyvery