I'm working on Zend application, but have no much experience with Zend, so just relying on my RubyOnRails experience.
From couple articles I've found that most of validation is implemented on Forms level - with Zend_Form. But it looks a bit weird for me - how about to have a validation on model level - create a model based on form data and run smth like $model->isValid();
it makes sense as I'm creating some models without forms post requests.
My current model flow:
ProductMapper extends Zend_Db_Table
Product extends Zend_Db_Table_Row
And given I'm doing something like
$mapper = new ProductMapper();
$product => $mapper->find(...);
// Do some staff with this model
// And want to check if it's valid before saving
if ($product.isValid()) {
$product.save(); // Zend_Db_Table_Row method
} else {
...
}
I realize that I can simply do validation with RegExp inside isValid
method, but I'd like to use already implemented methods from Zend_Form
like addValidator
, addFilter
and all that usefull things.
Also is this correct way to manage models in Zend?
Any help or suggestions will be very appreciated!