ErrorController for each module in ZF1

1

I have a project that uses Zend Framework 1. It has 2 modules: default and admin .

When an error occurs or exception , Zend directs to the ErrorController.

The problem is this: When an error occurs within the " default " module, it points to the ErrorController of the " default " module (this is correct). However, when an error occurs in the "admin" module, it also points to the ErrorController of the " default " module, causing the error to appear in layout site , instead of the layout of the admin.

I have an ErrorController in the "admin" module and I thought this was automatic. How do I direct the errors of the "admin" module to your ErrorController?

    
asked by anonymous 18.02.2015 / 20:20

1 answer

2

Reference: link

You can implement a plugin to examine your request and based on the module you are accessing it arrow the specific ErrorController ...

<?php
class My_Controller_Plugin_ErrorControllerSwitcher 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());
        }
    }
}

Then use the example below to register the plugin on your frontController

$front = Zend_Controller_Front::getInstance();
$front -> registerPlugin(new My_Controller_Plugin_ErrorControllerSwitcher())
    
18.02.2015 / 20:50