Skip to content

Instantly share code, notes, and snippets.

@ellor1138
Last active August 29, 2015 14:06
Show Gist options
  • Save ellor1138/083bf2f1cb1d4c8df77e to your computer and use it in GitHub Desktop.
Save ellor1138/083bf2f1cb1d4c8df77e to your computer and use it in GitHub Desktop.
CFWHeels model validation based on action
This will enable you to run CFWheels validation functions based on the params.action.
With this, you can validate certain properties only for certain actions.
Controller.cfc
Function setParamsValidation
Add params to the request scope.
YourController.cfc
Use a filter in your controllers to call setParamsValidation.
YourModel.cfc
In your models you use the condition argument of the validation function to specify with which action it should run.
<cfscript>
component extends="Wheels" {
public function setParamsValidation() {
request.paramsValidation = {
action = params.action
};
}
}
</cfscript>
<cfscript>
component extends="Controller" {
public void function init() {
filters(through="setParamsValidation");
}
}
</cfscript>
<cfscript>
component extends="Model" {
public void function init() {
validatesPresenceOf(properties="property", condition="request.paramsValidation.action EQ 'yourAction'");
}
</cfscript>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment