Handling Exceptions thrown in Zend Framework's Controller Plugins

bjc22

New Member
I have an Acl plug-in which extends \[code\]Zend_Controller_Plugin_Abstract\[/code\], this plug-in handles all my Acl code.I want to thrown an Exception in this plug-in, e.g. an \[code\]Exception_Unauthorised\[/code\] and then handle this in my \[code\]ErrorController\[/code\], this way I can use the same Acl plug-in for different applications and use the \[code\]ErrorController\[/code\] to handle each situation in each application differently - if need be.The problem is that throwing an Exception in the plug-in does not stop the original Action from executing. So I end up with the original Action's output and the \[code\]ErrorController\[/code\] output. How can I get an Exception thrown in a plug-in to stop the original Action from taking place?Case 1\[code\]// This throws the `Exception_NoPermissions`, but it does not get caught by// `ErrorController`public function preDispatch(Zend_Controller_Request_Abstract $request){ parent::preDispatch($request); throw new Exception_NoPermissions("incorrect permissions");}\[/code\]Case 2\[code\]// This behaves as expected and allows me to catch my Exceptionpublic function preDispatch(Zend_Controller_Request_Abstract $request){ parent::preDispatch($request); try { throw new Exception_NoPermissions("incorrect permissions"); } catch(Exception_NoPermissions $e) { }}\[/code\]Case 3I think this is where the issue is, by changing the controller. \[code\]public function preDispatch(Zend_Controller_Request_Abstract $request){ parent::preDispatch($request); // Attempt to log in the user // Check user against ACL if(!$loggedIn || !$access) { // set controller to login, doing this displays the ErrorController output and // the login controller $request->getControllerName("login"); }}\[/code\]
 
Back
Top