I am having an issue getting populate model to work..

<cfset var objUser = populateModel("user")>
<cfset objUser.addUser()>

After I do those lines of code, I thought that inside my model I would
have access to all values in the "rc" collection. Basically to test
this I did a CFDUMP of the RC collection in the function addUser() and
I got Variable RC is undefined. If someone could provide some guidance
that would be great..

RC is part of your Handler, your model wouldn't know anything about it
and shouldn't. Your model knows about the values that are sent into
it. Once they are sent in, they are part of the Arguments collection.

Abstracting away from the particulars of the populateModel and
populateBean methods, think of it this way.

Lets say your User bean takes 3 pieces of info, a first name, a last
name and an email address and you have an init function that invokes
your setters. All three of the following ways to create the User bean
would be equally valid:

CreateObject("User").init(first_name="Judah", last_name="McAuley",

last_name=form.last_name, email=form.email);

last_name=rc.last_name, email=rc.email);

Your User object doesn't care where the data is coming from. It just
gets a value for a first_name and does, internally,
instance.variables.first_name = arguments.first_name

Everything it sees comes in via the arguments scope. How you pass data
into object is your choice.

The populateModel and populateBean methods are convenience methods
that scan the request collection, which is itself a convenience
structure combining the url and form scopes, and uses the values to
send in matching arguments to your object, thus populating the
arguments structure of your object.

In a nutshell, your object should never know about the request
collection. All it knows about is the arguments scope. Hope that
helps. If you need further clarification, holler.


Are you saying if I have matching settings in my object it will automatically populate it from the request object?

so in my model's function If i had an argument named userid. Then
would this argument be automatically populated from the request

It seems like populatemodel() should be able to populate from a
request. This is what it says...

Easily populate model objects with data from a request: populateModel

In your handler you can use populateModel("User") without passing in
the Request Collection (RC). What ColdBox does is look at the setters
you have and try to match those up with the key names in the RC. So
you won't be able to call variables.rc inside your model as it doesn't
exist - the whole RC scope isn't injected, only the methods with
matching names to keys inside the RC struct are called .

Hope that helps,

- John

when you mean setters, do you mean cfproperty settings? If so can you provide an example of the model cfc?

“Setters” is a generic term that refers to the various set{PropertyName}() methods on an object. So, again using Judah’s User example, you would have the following setters:

ColdBox’s populateModel() convenience method, as John and Judah both mentioned, look for variables in the request collection that match up with setter names. So in this example, if the RC contains ‘firstName’, this…


… would internally call…


Presumably the RC would contain all three: firstName, lastName, and email. Without populateModel() you would have to do this in your controller…


With populateModel(), you simply do…


The more properties you need to set, the less code you have to write thanks to the convenience method.

The same result can be achieved by utilizing the proper ColdBox DSL. I would suggest reading the model integration guide (http://wiki.coldbox.org/wiki/Models.cfm) for a much more detailed explanation of how to put all the various pieces of the puzzle together.

Thank you very much for your detailed explanation!!