ZF-3053: The plugin solution to the exceptions handling doesn't work


class My_Controller_PreDispatchPlugin extends Zend_Controller_Plugin_Abstract
    public function preDispatch(Zend_Controller_Request_Abstract $request)
        $dispatcher = Zend_Controller_Front::getInstance()->getDispatcher();
        $controller = $dispatcher->getController($request);
        if (!$controller) {
            $controller = $dispatcher->getDefaultControllerName($request);
        $action     = $dispatcher->getAction($request);

        if (!method_exists($controller, $action)) {
            $defaultAction = $dispatcher->getDefaultAction();
            $controllerName = $request->getControllerName();
            $response = Zend_Controller_Front::getInstance()->getResponse();
            $response->setRedirect('/' . $controllerName . '/' . $defaultAction);

The dispatcher doesn't have a function getController() it does however have a getControllerClass which will return the className or false which is nice but still won't give you an initialized class to use for the action checking.

Also the headering to /:controller/:action is nice but it should be reverse routed first and have the $request->getBaseUrl() prepended.

I know it's example code but a proper working example would be nice.


Please evaluate and categorize/assign as necessary.


I am not too clear on what it is your plugin is trying to accomplish.. If you could explain your use case in a bit more detail, it would be easier to understand where you feel the bug is. Have you checked Matthews tutorial on the subject:…

perhaps that might help.

Thanks, Ralph

Unassigning until more info comes in

The idea is that it will check to see if the controller and action specified actually exist on the preDispatch. That way you can handle non existing actions and/or controllers in one place instead of getting and parsing the specific exception in the error handler.

It's not that I really need it, it's more that it's posted as example in the docs and it doesn't even work.

It's in paragraph 7.12.3 in the current docs.

Updating component to conform to new IT conventions.

I'm not entirely sure if this is an existing example or a proposed new example. Could the reporter clarify?

it's an existing non working example in paragraph 7.12.3… (at the bottom)

It should be changed to working code, or it should be removed because it does not work.

Fixed in trunk with r12821; will likely update on site with 1.7.1 release.