Define "Validation in the Model"

Posted by sunwukung on Stack Overflow See other posts from Stack Overflow or by sunwukung
Published on 2010-06-07T15:36:24Z Indexed on 2010/06/07 16:32 UTC
Read the original article Hit count: 201

There have been a couple of discussions regarding the location of user input validation:

http://stackoverflow.com/questions/659950/should-validation-be-done-in-form-objects-or-the-model

http://stackoverflow.com/questions/134388/where-do-you-do-your-validation-model-controller-or-view

These discussions were quite old, so I wanted to ask the question again to see if anyone had any fresh input. If not, I apologise in advance.

If you come from the Validation in the Model camp - does Model mean OOP representation of data (i.e. Active Record/Data Mapper) as "Entity" (to borrow the DDD terminology) - in which case you would, I assume, want all Model classes to inherit common validation constraints. Or can these rules simply be part of a Service in the Model - i.e. a Validation service? For example, could you consider Zend_Form and it's validation classes part of the Model? The concept of a Domain Model does not appear to be limited to Entities, and so validation may not necessarily need to be confined to this Entities.

It seems that you would require a lot of potentially superfluous handing of values and responses back and forth between forms and "Entities" - and in some instances you may not persist the data recieved from user input, or recieve it from user input at all.

© Stack Overflow or respective owner

Related posts about php

Related posts about validation