RC vs Event

Greetings. I'm new to ColdBox, and just need to clarify something.

In ColdBox 3.0, what object/structure should I be setting/getting
values in/from?

I've seen info about using rc, and other about using event.setValue/

Which is appropriate to use?

Thanks in advance.

You're always working with the event. It's just that "RC" is usually
set to act as a shorthand.

<cfset var RC = event.getCollection()>
<cfset var PRC = event.getCollection(private=true)>

- Gabriel

Welcome to ColdBox Russ!

The Event represents your user’s request and is passed around the framework to process a request. It is unique to each request and can’t impact any other requests. As Gabriel mentioned, the “Request Context” is a structure that will be populated with your URL and FORM variables.

Event.setValue({key},{value}) and Event.getValue({key}) essentially do this:

rc[#key#] = #value#.

You can use the Event methods–or–get a reference to “rc”/“prc” and do all normal struct operations on it. For example, Event.paramValue(“Foo”,“Bar”) would be similar to: if (!structKeyExists(rc, “foo”)) { rc.foo = “Bar” }; There is one cool thing you can do with the “getValue()” method… provide a default. Event.getValue(“foo”,“bar”); In this example, if FOO is not defined the function will return “bar”.

Keep the questions coming. Also, Luis offers ColdBox training. Perhaps something to consider.


There is no hard and fast way, or one better than the other, it will depend
more on you needs at the time.

For example if you are submitting a form then the following can be used to
retrieve the data.

<cfset var rc = event.getCollection() />

You can als just get the value you want by just doing

The best and maybe useful thing here is that the event.getValue() can also
act as a param define as well, for example the following will try to get the
form value, and if it is not available then it will return an empty value.

<cfset var formValue = event.getValue('formVarUsed','') />

On the same token the RC (Request Collection) also has a private version
that you can use with, and will not get trashed by form/url variables.
<cfset var rc = event.getCollection(private=true) />

Hope that helps, and as always do check out the documents on the wiki they
are also very informative.