I’m trying to access the final xhtml output right before it’s sent to the browser as a string. The postDispatch() methods of the actions and plugins seem to be too early to do this. When I step through Zend_Controller_Front::dispatch() method using a debugger, I can access the desired output as a string right before $this->_response->sendResponse() is called at the very end by adding a watch expression $this->getResponse()->getBody(). However, there seems to be no dedicated hook to tap into right there. I need the final response body as a string in order to send it to Prince XML to generate a pdf. Does anybody know an elegant way to do this?
Thanks, Adrian
The
Zend_Controller_Frontplugin hooks are the following (from here):routeStartup()is called beforeZend_Controller_Frontcalls on the router to evaluate the request against the registered routes.routeShutdown()is called after the router finishes routing the request.dispatchLoopStartup()is called beforeZend_Controller_Frontenters its dispatch loop.preDispatch()is called before an action is dispatched by the dispatcher. This callback allows for proxy or filter behavior. By altering the request and resetting its dispatched flag (viaZend_Controller_Request_Abstract::setDispatched(false)), the current action may be skipped and/or replaced.postDispatch()is called after an action is dispatched by the dispatcher. This callback allows for proxy or filter behavior. By altering the request and resetting its dispatched flag (viaZend_Controller_Request_Abstract::setDispatched(false)), a new action may be specified for dispatching.dispatchLoopShutdown()is called after Zend_Controller_Front exits its dispatch loop.So
dispatchLoopShutdown()is your hook to go – it’s the last thingZend_Controller_Front::dispatch()does before returning or sending the response.Another option could be, even though they were designed for something completely different, to use
Zend_Viewfilters. These filters can be added to theZend_View-instance and are called inZend_View::render(). A filter is simply an instance of a class that provides afilter($buffer)-method that returns the filtered$buffer. But using this interface for something not related to filtering the ouptut, seems not to be the correct way actually.I personally think, that a
dispatchLoopShutdown()-plugin will be the way to go.