简体   繁体   English

Zend:500错误而不是404

[英]Zend: 500 error instead of 404

Problem with 404 errors in Zend Framework 1. http://www.url.nl/path/wrong returns a 404 error (because the /path part exists). Zend Framework 1中出现404错误的问题。http ://www.url.nl/path/wrong返回404错误(因为/path部分存在)。 But when the first path is wrong (the root), it returns a 500 error. 但是,当第一个路径错误时(根目录),它将返回500错误。 So http://url.nl/wrong returns a 500. Anybody who experienced the same issue? 因此http://url.nl/wrong返回500。有人遇到过同样的问题吗? This is my error handler: 这是我的错误处理程序:

switch ($errors->type) {
            case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_ROUTE:
            case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_CONTROLLER:
            case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_ACTION:

                // 404 error -- controller or action not found
                $this->getResponse()->setHttpResponseCode(404);
                $this->view->message = 'Page not found '.$role;

                if (!$role) $this->_helper->layout->setLayout ( 'pages/404' );
                else $this->_helper->layout->setLayout ( '404' );

                break;
            default:
                // application error
                $this->getResponse()->setHttpResponseCode(500);
                $this->view->message = 'Application error';
                break;
        }

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


            $this->_helper->viewRenderer('error-no-access');
            $this->_helper->layout->setLayout ( '403' );            
        }

EDIT: The ACL manager was the problem, contained some problems in redirects etc. Most of the pages where redirected to the back-end and restricted because a normal user was trying to reach the page. 编辑:ACL管理器是问题所在,在重定向等中包含一些问题。大多数页面重定向到后端并受到限制,因为普通用户试图访问该页面。

/*if (!$role) $this->_helper->layout->setLayout ( 'pages/404' );
                    else $this->_helper->layout->setLayout ( '404' );

                    break;
                default:
                    // application error
                    $this->getResponse()->setHttpResponseCode(500);
                    $this->view->message = 'Application error';
                    break;*/

Try commenting the above section (like I did). 尝试评论上面的部分(就像我一样)。 This will tell you the actual problem at your file location(at your url). 这将在文件位置(URL)告诉您实际的问题。 Once you know the problem, you can solve it as well. 一旦知道了问题,就可以解决。

Hope it helps. 希望能帮助到你。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM