Welcome Guest, Not a member yet? Register   Sign In
Model and Form
#10

(12-12-2014, 03:21 PM)mwhitney Wrote: In most cases, I keep my validation rules in the model and have a method in the base model (get_validation_rules()) to return the validation rules. Then my controller can do the following:

Perhaps it's a matter of personal preference, but I don't agree with that method.  Form Validation is a natural function of the controller in my opinion.  It should be the first thing your controller does in most cases.  The controller is opening the door to your server when it accepts requests and form input.   The lock should be on the front door, not in the kitchen.

Forms pass data to a controller.   When that form data does not validate, the controller sends the data back to the user with error messages.  Why should the model enter into this clear request/response exchange when it is completely unnecessary?  Why should you even load a model if you know it's not going to be needed in the case of failed validation?
Reply


Messages In This Thread
Model and Form - by aurelien - 11-20-2014, 03:24 AM
RE: Model and Form - by Rufnex - 11-20-2014, 04:10 AM
RE: Model and Form - by ivantcholakov - 11-20-2014, 05:00 AM
RE: Model and Form - by bclinton - 11-20-2014, 07:59 AM
RE: Model and Form - by slax0r - 11-20-2014, 04:11 PM
RE: Model and Form - by RobertSF - 11-20-2014, 05:59 PM
RE: Model and Form - by bclinton - 11-20-2014, 07:26 PM
RE: Model and Form - by slax0r - 11-21-2014, 01:43 AM
RE: Model and Form - by bclinton - 12-12-2014, 04:58 PM
RE: Model and Form - by mwhitney - 12-12-2014, 03:21 PM
RE: Model and Form - by bclinton - 12-12-2014, 04:55 PM
RE: Model and Form - by mwhitney - 12-15-2014, 10:02 AM
RE: Model and Form - by jaynarayan - 12-18-2015, 10:44 AM



Theme © iAndrew 2016 - Forum software by © MyBB