2009年7月15日星期三

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

On 15 Jul 2009, at 16:02, Carlton Gibson wrote:

>
> On 15 Jul 2009, at 15:47, Exception e wrote:
>
>>
>>
>> Carlton Gibson-2 wrote:
>>>
>>> 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.
>>>
>>
>> Still no good result. Now the layout html is appended to the
>> template html.
>> We've lost the $this->layout()->content magic
>
> Sorry, you're dead right. (Except about it being magic :-)
>
> If you look at Zend_Layout_Controller_Plugin_Layout::postDispatch()
> you'll see that the content from the response object is there
> assigned to the layout instance. This I hadn't told you to do, which
> is why you don't get the content when you manually render the layout.
>
> So...
>
> //get the content into the layout
> $content['content'] = $this->view->render(path/to/view/script.phtml);
>
> $layout = $this->_helper->layout->getLayoutInstance();
>
> $layout->assign($content);
>
>
> //now capture the content
> $output = $layout->render();
>
> //continue
>
> (Hopefully)
>
>
>>
>> Btw, the only method to prevent zf of outputting anything I could
>> find is to
>> explicitly call
>>
>> $this->getResponse()->clearBody();
>>
>> So the question how Zend_Layout works is still important. The
>> workings are
>> hidden to users, but we need controll over its output in a controller
>> action.
>
>
>

没有评论: