View Single Post
  #16 (permalink)  
Old 09-02-2008, 01:26 PM
blinky001 blinky001 is offline
Junior Member
 
Join Date: Aug 2008
Location: Lancaster, UK
Posts: 2
Default

Found a work around online (credit to Daniel Cousineau). Apparently the ZF does not allow for multiple error controllers by default - God knows why not - it is very useful to be able to handle errors differently for different modules...

[PHP]<?php

class APP_Controller_Plugin_ErrorControllerSelector extends Zend_Controller_Plugin_Abstract
{

public function routeShutdown(Zend_Controller_Request_Abstract $request)
{
$front = Zend_Controller_Front::getInstance();

# If the ErrorHandler plugin is not registered, bail out
if(!($front->getPlugin('Zend_Controller_Plugin_ErrorHandler' ) instanceOf Zend_Controller_Plugin_ErrorHandler))
{
return;
}

$error = $front->getPlugin('Zend_Controller_Plugin_ErrorHandler' );

# Generate a test request to use to determine if the error controller in our module exists
$testRequest = new Zend_Controller_Request_HTTP();
$testRequest->setModuleName($request->getModuleName())
->setControllerName($error->getErrorHandlerController())
->setActionName($error->getErrorHandlerAction());

# Does the controller even exist?
if($front->getDispatcher()->isDispatchable($testRequest))
{
$error->setErrorHandlerModule($request->getModuleName());
}
}

} [/PHP]

and then in the bootstrap just register an extra plugin:

[PHP]<?php

$frontController->registerPlugin(new APP_Controller_Plugin_ErrorControllerSelector());

?> [/PHP]

Hope this helps someone else!
Reply With Quote