Error Handling for different modules on the Zend Framework

kill-the-bug

Error Handling is a default form for Exception treatment on the Zend Framework. The Framework will register the Zend_Controller_Plugin_ErrorHandler and this plugin will by default listen to all controllers and it will do whatever you set to do on the ErrorController ErrorAction defined by you.

Give it a check on the framework documentation: Zend Controller Plugins

The trouble starts when you need to have a new way to handle exceptions differently for each module. Let’s say for instance that the default module is the main site and the secondary module is the shopping cart or a cell phone site.

Just to make the example more clear, imagine that for each module you want to have a different way to display a 404 page.

The documentation correctly shows how to set the plugin in order to use another module, but it don’t show you where. For setting up the plugin to accept another controller, action and view to another module you need to set those rules under the constructor of the module bootstrap or under the constructor of the main bootstrap.

Considering that the following is under the bootstrap for the shopping cart module you would have:

public function __construct() {

$front = Zend_Controller_Front::getInstance();
$front->registerPlugin(new Zend_Controller_Plugin_ErrorHandler(array(
‘module’     => ‘shoppingcart’,
‘controller’ => ‘static’,
‘action’     => ‘error’
)));

}

For a reason which I could not understand until this moment, placing this plugin register in any other place will not work. Keep digging at it. Upates soon!!!

Have fun.

Advertisements

About mcloide

Making things simpler, just check: http://www.mcloide.com View all posts by mcloide

3 responses to “Error Handling for different modules on the Zend Framework

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: