zend-frameworkzend-acl

displaying page not found error with zend acl


whenever a controller is called if it is not registered in zend acl then we ususally get erro r like this

Fatal error: Uncaught exception 'Zend_Acl_Exception' with message 
'Resource 'hsfasfdadsf' not found' in /usr/share/php/libzend-framework-php/Zend/Acl.php:365
Stack trace: 
#0 /var/www/update/library/Management/Access.php(55): Zend_Acl->get('hsfasfdadsf') 
#1 /usr/share/php/libzend-framework-php/Zend/Controller/Plugin/Broker.php(309): Management_Access->preDispatch(Object(Zend_Controller_Request_Http)) 
#2 /usr/share/php/libzend-framework-php/Zend/Controller/Front.php(941):

isn't there a way to check if the controller and action is registered in zend acl, i tried

if(!$acl->get($controller))
{
    $request->setControllerName('error');
    $request->setActionName('notfound');
}

but did not work


Solution

  • First solution:

    Avoid those exceptions, e.g.

    if (!$acl->has($your_resource)) {
       // .. handle it the way you need
    }
    

    Second one

    Handle those exceptions in ErrorController, i.e.:

    if ($errors->exception instanceof Zend_Acl_Exception) {
        // send needed headers...
        // prepare log message...
        // render info: resource_not_found.phtml
        $this->_helper->viewRenderer('resource_not_found');
    }