使用zend acl显示页面未找到错误

San*_*kha 3 zend-framework zend-acl

无论何时调用控制器,如果它没有在zend acl中注册,那么我们通常会得到这样的错误

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):
Run Code Online (Sandbox Code Playgroud)

是没有办法检查控制器和操作是否在zend acl中注册,我试过

if(!$acl->get($controller))
{
    $request->setControllerName('error');
    $request->setActionName('notfound');
}
Run Code Online (Sandbox Code Playgroud)

但没有奏效

tak*_*hin 6

第一解决方案

避免这些例外,例如

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

第二个

在ErrorController中处理这些异常,即:

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');
}
Run Code Online (Sandbox Code Playgroud)