How to send Zend Framework error pages to custom pages?

I have members that can be blocked, and when a member is blocked, I want to send them to the user errors page, how would I do this in the zend framework? I tried

throw new Zend_Controller_Dispatcher_Exception('Your message here');

but he doesn’t say “your message is here,” he says “page not found” when I do this.

here is my error controller.

<?php

class ErrorController extends Zend_Controller_Action
{

public function errorAction()
{
    $errors = $this->_getParam('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';
            break;

            // 666 error -- controller or action not found
            $this->getResponse()->setHttpResponseCode(666);
            $this->view->message = 'Blocked';
            break;
        default:
            // application error
            $this->getResponse()->setHttpResponseCode(500);
            $this->view->message = 'Application error';
            break;
    }

    // Log exception, if logger available
    if ($log = $this->getLog()) {
        $log->crit($this->view->message, $errors->exception);
    }

    // conditionally display exceptions
    if ($this->getInvokeArg('displayExceptions') == true) {
        $this->view->exception = $errors->exception;
    }

    $this->view->request   = $errors->request;
}

public function getLog()
{
    $bootstrap = $this->getInvokeArg('bootstrap');
    if (!$bootstrap->hasPluginResource('Log')) {
        return false;
    }
    $log = $bootstrap->getResource('Log');
    return $log;
}

}

Here is the documentation, http://framework.zend.com/manual/en/zend.exception.using.html I don't understand: (

+5
source share
2 answers

Here are a few tips for his work.

no_route/no_controller/no_action. ( PHP Exception.

throw new My_Exception_Blocked('You are blocked');

, :

public function errorAction()
{
    $errors = $this->_getParam('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';
            break;

        // check for any other exception
        case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_OTHER:
            if ($errors->exception instanceof My_Exception_Blocked) {
                $this->getResponse()->setHttpResponseCode(403);
                $this->view->message = $errors->exception->getMessage();
                break;
            }
            // fall through if not of type My_Exception_Blocked

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

666 403, 6xx HTTP, / .

, .

+8

. , . Zend Framework . .

. .

Zend_Controller_Plugin_ErrorHandler , , ; , " MVC".

:

  • ,

  • ,

  • ,

, ErrorHandler HTTP 404 ( ) 500- ( ). , .

+5

All Articles