views:

53

answers:

1

How to I redirect to 404 page ("page not found") at preDispatch? Normally within action I can simply write:

throw new Zend_Controller_Action_Exception('Page is not found!', 404);

And it forwards to the appropriate page. How do I make it work for preDispatch?

A: 

Hi, this code snippet would help you

$request->setModuleName("module")->setControllerName("error")
                   ->setActionName("error")->setDispatched(true);

or you might use as well

$redirector =
    Zend_Controller_Action_HelperBroker::getStaticHelper('redirector');

consult the documentation for more information

tawfekov
I think it is better to forward, not to redirect to an error page. Just display the error on the current request uri by forwarding and then the user can refresh the page or go back.
David Caunt