Hi Ralf
If you were abstracting your classes to that degree, I'd define the
validators in your Zend_Db_Table model (on a per-model basis) and
provide rules for insertion and updating (or both). Then when creating
your forms, pass an instance of the model to that form in the
constructor and have it query each column it's required to add the
necessary validators.
You could probably create a 'base' set of rules simply by using the
Zend_Db_Table::info() values (e.g. null, type, etc.) and then add/
override each column via an array (or passed $config).
If it helps, Jack Sleight and I have a Zend_Db_Table plugin that may
be handy here - it has plugin points for pre/post operations (i.e.
update/save) that may help here - a plugin that auto-queries a model
before validating a form for example?
Hope my ramblings help (been a tough day here :)
Cheers
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
--
Simon Mundy | Director | PEPTOLAB
""" " "" """""" "" "" """"""" " "" """"" " """"" " """""" "" "
202/258 Flinders Lane | Melbourne | Victoria | Australia | 3000
Voice +61 (0) 3 9654 4324 | Mobile 0438 046 061 | Fax +61 (0) 3 9654
4124
http://www.peptolab.com