views:

27

answers:

2

I have been trying to find a way to capture the output (rendered view) of another action within the current action... something akin to output buffering.

The scenario is that I need to save a "snapshot" of a report. The data used in the report is ever-changing, and for whatever reason I need to actually save the view HTML rather than just a data array. I have created a snapshotAction(), and I want to somehow capture the output of the separate reportAction() within it. I don't want to render the reportAction() to the screen, I want it to render within my current action, before the action completes.

Is there any way to do this in ZF?


Correctly answered by Benedict Cohen below, but I didn't realize it until I saw this usage in the ZF mailing list archives: How to render multiple action views?

I am using something similar:

public function snapshotAction () {
    $content = $this->view->action('run', 'report');
    ...etc...
}
A: 

Take a look at this other post. The Zend_Cache classes may just help you find what you need.

Inkspeak
+1  A: 

There's a view helper called 'action' which may be helpful. You specify the controller and action and params and it returns the result. The helper creates a new dispatch loop so if you use it a lot it could have performance implications (I don't worry about performance until there's evidence that it's causing problems).

Benedict Cohen
A new dispatch loop is exactly what I need, but I'd like some way to do it within the controller action, for two reasons: I don't actually want to render the snapshot view (planning to make it an AJAX call, sorry I forgot to mention that), and also I'd have to process/save the report view from the snapshot view, which kind of breaks MVC convention. It WOULD work though, just shocked you can't do it from the controller.
wizzard
I take it back. I didn't think that you could call this from the controller for some reason, but it works perfectly. Will edit my question with more specific code.
wizzard