Hi,

I wonder what others think of the best practice for the validation part:

a) Keep the validation rules in the form objects and let Zend_Form
   handle the validation part

b) Keep the validation rules in the model object and let Zend_Db_Table
   handle the validation part by extending its insert() and update()
   methods

c) Keep the validation rules in the row object and let
   Zend_Db_Table_Row handle the validation part by extending its
   _insert() and _update() methods

The a) solution has the disadvantage of redundant validation rule
definitions, e.g. think about a user table which has a user_name and
only alphanumeric values and a length between 5 and 16 chars are
allowed. You will have a form for registration, for updating, for login
and for password recovery. All these forms expect the user_name as an
input and in all these forms you will need to add your validation rules.
If you want to change the maximum length to 64 chars you will need to
amend the validation rules for all these forms. The big advantage of
Zend_Form is the very nice integration of the validation part, though.

If I use the b) solution with a new validate() method which is called by
insert() and update() I will have another problem: for insertion or
updating there might be other fields to be mandatory (e.g. password in
registration is mandatory, while updating it is not). So I still will
probably work with a validateInsert() and a validateUpdate() method, not
to forget the validateLogin() and validatePasswordRecovery() methods.

None of these solutions seem to be the perfect solution. Maybe to keep
the validation on column level in Zend_Db_Table_Row and let Zend_Form
just define the mandatory / not mandatory part would be the best solution?

Any thoughts?

Thanks and best regards,

Ralf

Reply via email to