ahmedsafan86
ahmedsafan86

Reputation: 1794

Zend framework- how to stop execution and redirect to the error controller

I want to catch php errors so i used set_error_handler('handler_function') when i echo the error message , 'Zend_Controller_Response_Exception' with message 'Cannot send headers; headers already sent' is thrown when i used the following lines

$fc=Zend_Controller_Front::getInstance();
$fc->getResponse()->setBody($error);

an error happened 'call to setBody method of a non-object'

i tried to throw an exception from the error handler but this depend on the error occurring before bootstrapping is displayed directly after bootstrapping displayed in errorController i used $fc->throwExceptions(false) to ensure it will send exceptions to error controller

when i do nothing in the error handler the execution is continued

what i need is to have one place to handle all errors

if there is a way to redirect to the error controller with error in params this will be good

Upvotes: 1

Views: 1794

Answers (1)

Tomáš Fejfar
Tomáš Fejfar

Reputation: 11217

IMO best way to handle these errors is to register error handler that will convert any error/fatal error to exception. I guess that response is not created yet. You have to use $fc's setResponse() method to create new response. I would guess that converting to exception should work in any case. Same as exceptions from Zend classes work.

Upvotes: 2

Related Questions