views:

127

answers:

2

Zend_Controller_Plugin_ErrorHandler always forwards to ErrorController::errorAction() in the default module but i want it be module aware. For example when a exception throws it must be call the module's ErrorController like Admin_ErrorController:errorAction.

How can i do this? Thanks.

+4  A: 

You can create plugin that will examine your request and based on current module sets ErrorController...

<?php
class My_Controller_Plugin_Utilities extends Zend_Controller_Plugin_Abstract
{
    public function routeShutdown (Zend_Controller_Request_Abstract $request)
    {
        $front = Zend_Controller_Front::getInstance();
        if (! ($front->getPlugin('Zend_Controller_Plugin_ErrorHandler') instanceof Zend_Controller_Plugin_ErrorHandler))
            return;
        $error = $front->getPlugin('Zend_Controller_Plugin_ErrorHandler');
        $testRequest = new Zend_Controller_Request_HTTP();
        $testRequest->setModuleName($request->getModuleName())
            ->setControllerName($error->getErrorHandlerController())
            ->setActionName($error->getErrorHandlerAction());
        if ($front->getDispatcher()->isDispatchable($testRequest)) {
            $error->setErrorHandlerModule($request->getModuleName());
        }
    }
Tomáš Fejfar
You may use $front->hasPlugin($name);
takeshin
A: 

Alternate approach may be to throw specific exceptions for each module (or functionality you need, e.g. Mymodule_MyException) and then handle them in the Default_ErrorController.

takeshin