models/User.cfc
controllers/Users.cfc
views/users/index.cfm
config()
method of your model. This keeps everything nice and tidy because another developer can check config()
to get a quick idea on how your model behaves.firstName
, lastName
, email
, age
, and password
fields must be provided, and they can't be blank.firstName
and lastName
can each be up to 50 characters long.email
cannot already be used in the database.age
can only be an integer.password
must be provided twice, the second time via a field called passwordConfirmation
.config/settings.cfm:
config()
method.when
, condition
, and unless
.when
argument accepts 3 possible values.onSave
(the default)onCreate
onUpdate
condition
and unless
provide even more flexibility when the when
argument isn't specific enough for your validation's needs.condition
specifies when the validation should be run. unless
specifies when the validation should not be run.validateEmailFormat
, which in this case would verify that the value set for this.email
is in the proper format. If not, then the method sets an error message for that field using the addError()function.IsValid()
is a function build into your CFML engine.newUser
based on the user
model and the form inputs (via the params
struct).<cfif>
test. If the save succeeds, the save() method will return true
, and the contents of the <cfif>
will be executed. But if any of the validations set up in the model fail, the save() method returns false
, and the <cfelse>
will execute.<cfelse>
renders the original form input page using the renderView()function. When this happens, the view will use the newUser
object defined in our save() method. If a redirectTo() were used instead, the validation information loaded in our save() method would be lost.passwordConfirmation
was provided so that the validatesConfirmationOf() validation in the model can be properly tested.config/settings.cfm
.[property]
to the message string. Wheels will automatically separate words based on your camelCasing of the variable names.message
.config()
method of our model: