Rawlins
February 11, 2011, 11:56am
1
Hello Guys,
I’m playing with routes for the first time this morning, trying to define a custom one.
addRoute(pattern=":service-key/status", handler=“Services”, action=“status”);
However, when I try and browse to http://localhost/some-service-key/status
I get an exception saying that The event: some-service-key.status is not valid registered event.
This would suggest to me that it’s using the default route of :handler/:action instead of matching my custom route.
Any suggestions? What am I doing wrong here?
Thanks chaps,
Robert
Aaron1
February 11, 2011, 12:07pm
2
Can you please attach your Routes.cfm configuration file? Also, what version of ColdBox are you using?
Thanks.
-A
Rawlins
February 11, 2011, 12:10pm
3
HI Aaron,
This is 3.0.0 RC2 from GitHub about a week ago.
My Routes.cfm looks like this: http://pastebin.com/bQRexdMn
Thanks,
Robert
Aaron1
February 11, 2011, 12:32pm
4
Good news! The fix is simple:
ColdBox has a feature that allows you to qualify the variable to be of a specific type. Here is an example:
/test/:id-numeric
Once I changed your route from :service-key/status to “:service_key/status” everything worked as expected as ColdBox was no longer trying to confirm the type of the variable. This is probably a bug in ColdBox as I would expect it to only match “-numeric”.
To resolve, simply rename your variable to no longer have a dash ("-").
Aaron Greenlee
http://aarongreenlee.com/
Rawlins
February 11, 2011, 12:52pm
5
Great stuff Aaron,
That makes perfect sense, i can see why that would be a problem
When you say it allows you to specify a type, can that be any type? or does it only support numeric?
Thanks,
Robert
Aaron1
February 11, 2011, 1:29pm
6
Good questions! This type validation is very powerful.
You can do simple evaluations such as “:foo-numeric/status” or “:foo-alpha/status”.
You can also perform custom validation using a regular expression such as “regex:{your regex here}/status”.
Cool stuff!
Rawlins
February 11, 2011, 1:30pm
7
Ah, that is very cool.
I like that a lot.
Thanks for the help this Aaron, really appreciate it.
Robert
lmajano
February 11, 2011, 3:55pm
8
Also as a suggestion try to make the first part of a route static thy
way you have more permutations available.