2009年7月15日星期三

Re: [fw-mvc] howto: capture action output, stream it as pdf


On 15 Jul 2009, at 14:50, Exception e wrote:

Carlton Gibson-2 wrote:
> But I want to capture the whole layout, including its content. > Ah, okay.

(This is just off the top of my head...)

//render the current action's view script via the ViewRenderer
$this->_helper->ViewRenderer->render();

//render the layout manually and capture the output
$output = $this->view->render(path/to/layout.phtml);

//disable the layout
$this->_helper->layout->disableLayout();

Try that.

Well, I did, but then the $output becomes the layout only, without its contents. What I need to capture is the whole layout, including its content. Pfew, this use case shouldn't be so difficult, but I am quitte puzzled?
calling
$this->_helper->ViewRenderer->render();
should influence

//render the layout manually and capture the output
$output = $this->view->render(path/to/layout.phtml);


but it doesn't. Unfortunately, zend_layout is a bit of black magic.


Okay, let's have another go. Zend_Layout's not magic. It's just particular. (And I'm trying to remember how it works without looking. :-)

The idea behind this: 
$this->_helper->ViewRenderer->render()

was to get the content of the current action's view script into the Response object so that when you render the layout manually, the bit which goes:

echo $this->layout()->content; 

has something to work on. That you're just getting the layout suggests that something has gone wrong.

The old fashioned way of doing all this would be: 

$response = $this->getResponse();
$response->appendBody($this->view->render(path/to/view/script.phtml));

You could try that. 

没有评论: