質問

So my Zend Framework keeps refusing to handle exceptions, despite me doing everything that everyone suggests on Google... So I'm here to ask what I may be doing wrong...

I have my ErrorController.php file set in app/modules/default/controllers, with this content :

<?php
class ErrorController extends Zend_Controller_Action
{
    public function errorAction()
    {
        $error = $this->_getParam('error_handler');
        switch ($error->type){
            case "EXCEPTION_NO_CONTROLLER":
            case "EXCEPTION_NO_ACTION":
                $this->getResponse()->setHttpResponseCode(404);
                $this->view->title = "Page Not Found";
                $this->view->message = "404 - Oops ! You took a wrong turn...";
                break;
            default:
                $this->getResponse()->setHttpResponseCode(500);
                $this->view->title = "Unexpected Error";
                $this->view->headmessage = "500 - Oops ! Something wrong happened... ";
                $this->view->message     = $error->exception->getMessage();
                break;
        }
        $this->view->exception = $error->exception;
        // pass the request to the view
        $this->view->request   = $error->request;
    }
}

In my index.php, I simply include app/bootstrap.php which contains, among other things:

$front = Zend_Controller_Front::getInstance();
$front->throwExceptions(false);
$front->setControllerDirectory('./application/controllers');
$front->registerPlugin(new Zend_Controller_Plugin_ErrorHandler());

Yet any time in my code I call, for example:

throw new Zend_Controller_Exception('This page does not exist', 404);

I get the usual annoying "Fatal error: Uncaught exception 'Zend_Controller_Exception' with message 'This page does not exist'" and blah blah blah...

Is there something I'm doing wrong? I wonder if that './application/controllers' thing is right, since to my knowledge there is not a single "application" folder in my Zend framework folder... but I cannot find anything about it online! And creating one to put my ErrorController.php in it led me nowhere so far...

役に立ちましたか?

解決

Alright, as it turns out, my Authentication Plugin was conflicting with the redirection (I have now learned that it is a pretty common issue), so I managed to fix it by fiddling with the rules of my authentication plugin.

Notably, 404 error redirections have to be handled within the Authentication Plugin by checking the route using the "isDispatchable" method and "manually" changing the routes towards a specific 404 page.

Well at least that did it for me, but the important thing to know is that there is no single solution to Authentication Plugin conflicts because every authentication plugin is different, depending on the purpose of it.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top