How to capture a Zend view output instead of actually outputting it -


Issue: Sometimes in our Zend Controller, we do not want to directly output scripts but rather the contents of the script . An example: When we require the output of a visible script HTML output, then the client is included in any other structure like JSON or XML for processing.

I found the result here on stack overflow, but not so fast as it was in a different context. I am struggling with this for two days. As it turned out, it was very simple:

// In our method of verbatim, $ the-> _helper-> Layout () - & gt; SetLayout ('empty'); // Inactive Layout $ - THIS- & gt; _helper-> Visual Trainer- & gt; Setenorender (true); // Make sure that the script is not being sent // your any code here $ html = $ this- & gt; View- & gt; Render ('projects / climate.phtml'); Return the visual script content as // string $ json = array ('html' = & gt; $ html, 'init data' = & gt; 'my other required data'); Echo json_encode ($ json);

I hope it was clear and useful to anyone.

public myAction () {$ this- & gt; _helper-> Json (array ('html' = & gt; $ this-> view- & gt; render ('projects / climate.phtml'), 'initData' = & gt; 'my other essential data',)) ;

Normally Jason Action Helper

  • Disable viewRenderer
  • Disable the layout
  • json_encode array

Comments