Comments: Routes Configuration

By silverquick on 18/6/08

1 - Using subpatterns

If you use regexp subpatterns (i.e. parenthetical groups) in the matching regexps, be careful to make them NON-CAPTURING subpatterns, otherwise you will get unexpected/useless results. (Although it appears if the parentheses enclose the entire string, there's no problem.)

For example, taking the above example from "Defining Routes", if you want to make sure the 'year' is either 19xx or 20xx, this will not work as expected:

...'year' => '(19|20)[0-9]{2}'...

You have to do this instead:

...'year' => '(?:19|20)[0-9]{2}'...

However, in the original example, month and day will work fine, because the whole string is enclosed in (...).

I don't think this is really a bug, just a side-effect of the way Cake matches URLs, so it seems worth adding to the manual.

By villas on 28/6/08

2 - Excellent Article on Routing

See also this article by Nate Abele (a lead developer of Cake). It contains additional helpful info and explanations:

http://c7y.phparch.com/c/entry/1/art,cake-seo