使用服务层时如何处理错误?

| 在我的Zend Framework项目中,我使用服务层,但是我真的不知道在哪里处理错误。 例如,假设我有一个“ 0” 如果我已经:
$data = array(
   \'userId\' => 2,
   \'firstName\' => \'Jane\',
   \'lastName\'  => \'Doe\',
);
并且ID为2的用户不存在吗? 您在哪里以及如何处理此类错误?     
已邀请:
您可以转发到特定的控制器来处理所有业务错误,如下所示:
if ($error=true)
        return $this->_forward(\'standarderror\', \'businesserror\', \'default\',
                array(\'msgtitle\' => $this->view->translate(\'item_not_found\'),
                    \'msg\' => $this->view->translate(\'item_not_found_msg\')));
以及您的BusinesserrorController如下所示:
class BusinesserrorController extends Zend_Controller_Action {

public function init() {
    $this->_helper->viewRenderer->setNoRender();
}

public function standarderrorAction() {
    $msgtitle = $this->_getParam(\'msgtitle\');
    $msg = $this->_getParam(\'msg\');

    $this->view->errortitle = $msgtitle;
    $this->view->errormessage = $msg;

    $this->view->nextstep = $this->view->translate(\'return_to_the_homepage\');
    $this->view->nextstepurl = \"/\";

    echo $this->render(\'error/businesserror\', null, true);
}

}
您也可以参数化转发的URL;)     

要回复问题请先登录注册