Last active
August 29, 2015 14:06
-
-
Save ellor1138/083bf2f1cb1d4c8df77e to your computer and use it in GitHub Desktop.
CFWHeels model validation based on action
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<cfscript> | |
component extends="Wheels" { | |
public function setParamsValidation() { | |
request.paramsValidation = { | |
action = params.action | |
}; | |
} | |
} | |
</cfscript> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<cfscript> | |
component extends="Controller" { | |
public void function init() { | |
filters(through="setParamsValidation"); | |
} | |
} | |
</cfscript> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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