Handling Error in zend framework1

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Handling Error in zend framework1

tarun
This post has NOT been accepted by the mailing list yet.
Hi All,
I am usign zend_filter_input to validate user supplied data in my model class.

class Site_Model_Users
{
   protected function _validateRegistrationForm()
  {

  }

  public function register($data)
  {
      if($input=$this->_validateRegisterForm($data))
      {
         return false; #if validation failed,return false to controller
     }
  }

}

Inside My controller class

public function registerAction()
{
   if(!$this->_model->register($postData))
   {
      //If Validation fails then add error message to view object
  }
}

Question : How should i pass error message from model to controller.If i write method like getErrorMessage then these messages are going to repeated in all model class so should i create an object like ErrorHandler?

If I ever have to change error message(part of view) i have to make changes in my model class(where i am validating my input) so how should i eliminate this dependecy of model class onto view.

Please  suggest some good method to handle errors in zend framework,Thanks
luk
Reply | Threaded
Open this post in threaded view
|

Re: Handling Error in zend framework1

luk
tarun wrote
Hi All,
I am usign zend_filter_input to validate user supplied data in my model class.

class Site_Model_Users
{
   protected function _validateRegistrationForm()
  {

  }

  public function register($data)
  {
      if($input=$this->_validateRegisterForm($data))
      {
         return false; #if validation failed,return false to controller
     }
  }

}

Inside My controller class

public function registerAction()
{
   if(!$this->_model->register($postData))
   {
      //If Validation fails then add error message to view object
  }
}

Question : How should i pass error message from model to controller.If i write method like getErrorMessage then these messages are going to repeated in all model class so should i create an object like ErrorHandler?

If I ever have to change error message(part of view) i have to make changes in my model class(where i am validating my input) so how should i eliminate this dependecy of model class onto view.

Please  suggest some good method to handle errors in zend framework,Thanks
Don't handle any errors in Models. Do it in your Controllers. To handle errors correctrly throw Exceptions and handle them by try {} catch(){}.
Cheers, -- Luke Mierzwa