RE: [coldbox:8307] Re: lost in a world of events - one handler one webpage?

So, basically the default route in ColdBox can be found in your /config/routes.cfm file and it looks like this:


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.



Ok so all my entire site is going to be served from the index.cfm. CB
all the way baby!


Could I technically have a handler nested deeply in the handlers
folder like so:
/handlers/aaa/bbb/ccc/ddd/eee/FFF.cfc with an action called GGG
and I don't have to modify the default
addRoute(pattern=":handler/:action?"); ??

Or do I need to add another route?

These are my last questions I swear. I want to play with this already.
Its seriously addicting learning this framework.

It should be noted that it appears to be served through the index.cfm, but
in reality it is done through the Application.cfc and executed well before
the index.cfm is even reached.

Very masterful illusion if you're not aware of it.

Andrew Scott

From: [] On
Behalf Of Daniel Mejia
Sent: Saturday, 26 February 2011 6:15 AM
To: ColdBox Platform
Subject: [coldbox:8316] Re: lost in a world of events - one handler one

Ok so all my entire site is going to be served from the index.cfm. CB all


what can the index.cfm be used for?

Running older applications inside ColdBox, but to be honest I can't see a
real benefit of using it. Others might have different ides though.

If you look at the index.cfm it is actually empty, apart from comments.

Andrew Scott