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

发布于 2024-10-14 17:40:12 字数 769 浏览 6 评论 0原文

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

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

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

但没有成功

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

总以为 2024-10-21 17:40:12

第一个解决方案:

避免这些异常,例如

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

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');
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文