0
votes

In Zend Framework,I am validating user supplied data in my model class something like

public function valiateRegisterForm($regisInfo)
{
   //validating with zend_filter_input which on failure returns array of arrays i.e
  //(error code to array of error messages) 
}

Right now i have create one more method getErrorMessage() to let controller to fetch error message from model but then i have to create this method in my every model class which will lead to redundancy,so should i create another object like ErrorManager?

To me it seems like as if am just not following things in proper way
please suggest some good method to handle error in zend framework.

1

1 Answers

1
votes

Possible iam not understanding your questions but, i would return the Zend_Filter_Input object from your "validateRegisterFrom" method.The Object has an "getMessages" method wich returns the validation errors.

public function valiateRegisterForm($regisInfo)
{
      $filters = array();
      $validators = array();

      $input = new Zend_Filter_Input($filters, $validators, $regisInfo);

      // do validating

      return $input;
 }

and in your Controller

public function whateverAction()
{
     $result = $My_Model_Register->validateRegisterForm($data);

     if ($result->hasInvalid()) {
         $errors = $result->getMessages();
     }
}