[Tip of the Week] Action Arguments in Your Handlers

The methods in your handlers (actions) have always accepted the “event” object, which is the request context for that event and contains things like the request collection and private request collection.

A common handler method used to look like this:

function index(event) {
var rc = event.getCollection();
var prc = event.getCollection(private=true);
// Do Stuff
}

Remember, if you’re using ColdBox 3.1 or higher, every action is now passed a reference to the request collection (rc) and private request collection (prc) as arguments so you don’t have to get them yourself.

function index(event,rc,prc){
rc.foo = “Isn’t this convenient?”;
prc.bar = “Yes, yes it is.”;
}

Remembering this tip can help clean up your code by omitting those uneccessary boilerplate lines of code to get the rc and prc.

More info here: http://wiki.coldbox.org/wiki/EventHandlers.cfm#Anatomy_of_an_Event_Handler_Action

Thanks!

~Brad

ColdBox Platform Evangelist
Ortus Solutions, Corp

E-mail: brad@coldbox.org
ColdBox Platform: http://www.coldbox.org
Blog: http://www.codersrevolution.com