So, basically the default route in ColdBox can be found in your /config/routes.cfm file and it looks like this:
addRoute(":handler/:action?")
That means that the first bit of text after index.cfm will be the handler followed by a slash and an optional event.
Anything else after the end of the route will be turned into name/value pairs.
It’s also worth noting that you can create packages, or folders to put your handlers in. If you had the following handler on your hard drive:
/handlers/business/ehIncentives.cfc that had a method called “vacations”
then in the URL it would be index.cfm/business/ehIncentives/vacations
It’s also worth noting that the “eh” bit at the start of the handler name is not required, it’s just a convention I’m used to where I work. Same with “vw” before my views.
So whether you want to put everything related to the business portion of your site in an ehbusiness handler, or create folders (packages) and nest related handlers, that’s up to you.
The awesome part of routes are, you can declare your own and get as funky as you want. For instance, if you place this in your routes.cfm config file:
<cfset addRoute( pattern="/business/incentives/vacations/overview", handler=“ehBusiness”, action=“incentiveVationsOverview” )>
Then you can hit “index.cfm/business/incentives/vacations/overview” and ColdBox will call the incentiveVationsOverview method in the ehBusiness handler. (Don’t forget a rewrite engine can easily get rid of the “index.cfm” part too!)
Or you could make it a bit more dynamic and do:
<cfset addRoute( pattern="/business/incentives/vacations/:area?", handler=“ehBusiness”, action=“incentiveVations” )>
That will give you an optional value in the request collection called “area” which will be equal to whatever text was found in that portion of the route. The sky’s really the limit on what you want to do:
<cfset addRoute( pattern="/business/:majorArea?/:moreSpecific?/:reallyReallySpecific?", handler=“ehBusiness”, action=“index” )>
That last example would let you route ALL requests that start with “business” through the index method in ehBusiness and conditionally display whatever views (or run additional events with runEvent()) based on the majorArea, moreSpecific, and reallyReallySpecific variables in the request collection.
In my site, we store content in the database (either straight-up HTML, or a dynamic handler/event to call) and and we pull that information and display it based on a slug that comes in the route. In that way, we actually route our entire site through one front end handler and event that just turns around and delegates to different handlers on the back end.
Thanks!
~Brad