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

标签 zend-framework zend-acl

每当 Controller 被调用时,如果它没有在 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):

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

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

但没有成功

最佳答案

第一个解决方案:

避免这些异常(exception),例如

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

第二个

在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');
}

关于zend-framework - 使用 zend acl 显示页面未找到错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4817282/

相关文章:

security - 访问控制列表最佳实践 - ACL - 为攻击站点的用户设置负面角色

php - Zend ACL 是否适合我的需求?

zend-framework - Zend_Acl,如何检查具有多个角色的用户的资源访问权限

php - Ajax Post : Array of Object posted , 无法在 php 端检索

mysql - 如何提高 zend paginator 分页的性能

php - 数据库无法连接到 Zend Framework

javascript - 提交表单后如何从 URL 中删除参数?

使用 Zend Auth 和 Zend ACL 进行 PHP 单元测试

php - 如何在 Zend Framework 2 中为变量值构建 ACL 断言?

php - 使用 Zend Json Server,ajax 调用在 css 弹出窗口中列出某些信息