I am using the Zend MVC framework along with an ORM layer generated with Propel, and I'm trying to figure out the best way to catch exceptions from a Propel object's save() function, and throw them to the Zend Form as errors.
Not all of the exceptions that come out of the Propel object have a way to identify which field caused the error, so I'm wondering if there is a way to add generic error messages to the entire form, rather than being forced to attach each error message to a particular form element.
For example, I have a save() call wrapped in a try/catch block, and I can add the exception->getMessage() to a form element's errors:
try {
$obj->save();
echo 'object saved successfully';
} catch (Exception $e) {
$form->name->addErrorMessage($e->getCode()." - ".$e->getMessage());
$form->name->markAsError();
$form->populate($formData);
}
but I would like to be able to do something like this:
try {
$obj->save();
echo 'object saved successfully';
} catch (Exception $e) {
$form->addErrorMessage($e->getCode()." - ".$e->getMessage());
$form->markAsError();
$form->populate($formData);
}
I hope that makes sense, thanks for the help,
Dave