> -----Original Message-----
> From: news [mailto:[email protected]] On Behalf Of Colin Guthrie
> Sent: 27 February 2009 14:56
> To: [email protected]
> Subject: [fw-general] Re: How to dispatch a 404 error
> 
> 'Twas brillig, and gllop at 27/02/09 10:07 did gyre and gimble:
> > I'm trying to thow a Zend_Controller_Action_Exception to dispatch a 404
> page
> > error. The ErrorController and the Plugin_Handler instance are already
> > implemented but I don't know how can i exactly dispatch the exception. I
> > supose it will be something like:
> > throw new Zend_Controller_Action_Exception('Error exception');
> >
> > But this don't render my corresponent 404 page. I get only "Error
> exception"
> > message.
> >
> > Any help would be apreciated. Thx!
> 
> Not sure if it's the right approach but I have a nonfound action in my
> default module's error controller.
> 
> I _forward to this from indexAction if I don't handle the error in some
> other way.
> 
> In some cases I also specifically forward to this action.
> 
> 
>    public function notfoundAction()
>    {
>      $this->getResponse()->setRawHeader('HTTP/1.1 404 Not Found');
>      $this->getResponse()->appendBody('<p>Not found</p>');
>    }
> 
> There are probably more elegant ways to get the same result tho'.
> 
> Col
> 
> --
> 
> Colin Guthrie
> gmane(at)colin.guthr.ie
> http://colin.guthr.ie/
> 
> Day Job:
>    Tribalogic Limited [http://www.tribalogic.net/]
> Open Source:
>    Mandriva Linux Contributor [http://www.mandriva.com/]
>    PulseAudio Hacker [http://www.pulseaudio.org/]
>    Trac Hacker [http://trac.edgewall.org/]


I not so sure this will help you but here is my errorAction from ErrorController

  public function errorAction()
    {
        $errors = $this->_getParam('error_handler');
        switch ($errors->type) {
            case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_CONTROLLER:
                $this->view->message = "No controller is available to service 
your request.";
                $this->getResponse()->setRawHeader('HTTP/1.1 404 Not Found');
                break;
            case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_ACTION:
                // 404 error -- controller or action not found                
                $this->getResponse()->setRawHeader('HTTP/1.1 404 Not Found');
                $this->view->title = 'HTTP/1.1 404 Not Found';
                $this->view->message = "Sorry the page you requested has not 
been found.";
                break;
            default:
                // application error; display error page, but don't change      
          
                // status code
                $this->view->title = 'Application Error';
                $this->view->message = 
                "An unexpected error has occured, please copy and paste the 
message below and mail to 
                        <a 
href=\"mailto:[email protected]\";>[email protected]</a><br 
/><br />";
                
                $this->view->message .= "<code>".$errors->exception."</code>";
                break;
        }
}

You could replace the default action etc...  Hope this helps,


Simon Griffiths

Reply via email to