views:

81

answers:

1

I'm trying to resolve this URL Route:

Route articlesByCategory = new Route("articles/c{cid}-{category}", new Handler);

However, it seems like the following url won't resolve to this route:

// doesn't work
www.site.com/articles/c24-this-is-the-category-title

// This works
www.site.com/articles/c24-category

I assume it has to do with the dashes in the title, but can anyone tell me why this works this way?

Is there a way to allow dashes in the title for a URL route like this?

+1  A: 

Which hyphen is the delimiter?

Server doesn't know which hyphen in your URL is delimiting cid from category. That's why it can't work. You could solve this by using something else than dashes in your category value. Or write a custom Route class that will be more flexible with definitions.

This answer on Stackoverflow may help you, because it can easily be used in your case...

Robert Koritnik
I have a constraint on {cid} which only allows numbers. It's prefaced by c. I would have assumed it would have used a regular expression like "articles/c[0-9]{1,6}-.*/" behind the scenes but I'm don't know enough about how the Routing engine matches routes to know exactly. It would appear to only respect the forward slash as a concrete delimiter.
Atømix
Just checked out that answer. RegexRoute... interesting.
Atømix
@Atomiton: Constraints are checked **after** route has already determined that a particular request should be handled by this route (by it's URL definition). Steps: Route tries to parse incoming request against its URL definition. If parsing succeeds, URL variables (as defined in route URL definition) are checked against constraints. In your particular case, parsing fails. Constraint checking does not execute at all.
Robert Koritnik
@Robert. Excellent comment! I had assumed it worked like a Regex, but your explanation makes more sense, now. I'm also thinking it parses from RTL. Have you got a source for more information about how it works? I saw your post here: http://stackoverflow.com/questions/2378222#answer-2381181 on the other question. Also very helpful. Thanks!
Atømix