2

私の Zend Framework プロジェクトでは、サービス層を使用していますが、エラーを処理する場所がよくわかりません。

たとえば、私が持っているとしましょうUserService::updateUser($data);

私が持っている場合:

$data = array(
   'userId' => 2,
   'firstName' => 'Jane',
   'lastName'  => 'Doe',
);

そして、ID 2 のユーザーは存在しませんか?

そのようなエラーをどこでどのように処理しますか?

4

1 に答える 1

1

次のように、特定のコントローラーに転送して、すべてのビジネス エラーを処理できます。

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もパラメータ化できます;)

于 2011-05-15T23:29:10.433 に答える