I am making a web application, and I need to sanitize and validate input data (e.g. data passed to a REST service).
I have already read that input validation belongs to the model, in the MVC paradigm.
I am now wondering what's the best DRY approach to do this. Currently my code looks pretty much like the following:
class myModel
{
public static foo($input1, $input2)
{
/*INPUT1 VALIDATION*/
/*...*/
/*INPUT2 VALIDATION*/
/*...*/
/*IF AT THIS POINT THE METHOD HAS NOT RETURNED YET, PROCEED WITH THE ACTUAL CODE*/
/*...*/
}
}
In this way, though, validation is repeated multiple times, once for each method call of the model.
Does a better approach exist?
Aucun commentaire:
Enregistrer un commentaire