A small ColdBox Tip

On April 15, 2009, in ColdFusion, by Anuj Gakhar

I have been using ColdBox for a few months now and I absolutely love it.  Althought I havent used all the features it has to offer, I like the URL rewriting feature a lot.

In one of my projects, my routes.cfm had quite a few routes added that looked like this.

[xml]
addRoute(pattern="contactus", handler ="ehPages", action="dspStatic")
[/xml]

Now, basically, what this does is sends the request to dspStatic action which reads the contents of the page from database and passes on to the view. I wanted to set a variable for which pagename to get from the database in the route file itself so I could share the same action for different pages. Thats when I looked at “matchVariables” attribute. I used it as documented and it wasnt working.

Apparently, it was introduced in 2.6.3 and I was using 2.6.2 . Thanks to Luis for clarifying this to me.  But there is also an undocumented way of doing this with earlier versions.

[xml]
addRoute(pattern="contactus", handler ="ehPages", action="dspStatic", pagename="contactus")
[/xml]

So, you can pass your extra variables in the route file and they would be available in the request scope. Thats pretty cool I think!

I thought this little tip might save someone some troubleshooting/debugging time.

Tagged with:  

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

© 2011 Anuj Gakhar
%d bloggers like this: