English 中文(简体)
Zend Framework: How can I tap into the final view output before it s sent to the browser?
原标题:

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_Front plugin hooks are the following (from here):

  • routeStartup() is called before Zend_Controller_Front calls on the router to evaluate the request against the registered routes.
  • routeShutdown() is called after the router finishes routing the request.
  • dispatchLoopStartup() is called before Zend_Controller_Front enters 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 (via Zend_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 (via Zend_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 thing Zend_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_View filters. These filters can be added to the Zend_View-instance and are called in Zend_View::render(). A filter is simply an instance of a class that provides a filter($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.

问题回答




相关问题
Brute-force/DoS prevention in PHP [closed]

I am trying to write a script to prevent brute-force login attempts in a website I m building. The logic goes something like this: User sends login information. Check if username and password is ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

定值美元

如何确认来自正确来源的数字。

Generating a drop down list of timezones with PHP

Most sites need some way to show the dates on the site in the users preferred timezone. Below are two lists that I found and then one method using the built in PHP DateTime class in PHP 5. I need ...

Text as watermarking in PHP

I want to create text as a watermark for an image. the water mark should have the following properties front: Impact color: white opacity: 31% Font style: regular, bold Bevel and Emboss size: 30 ...

How does php cast boolean variables?

How does php cast boolean variables? I was trying to save a boolean value to an array: $result["Users"]["is_login"] = true; but when I use debug the is_login value is blank. and when I do ...

热门标签