× {{alert.msg}} Never ask again
Get notified about new tutorials RECEIVE NEW TUTORIALS

How to use context switcher json/xml on Zend Framework ?

BRETON
Oct 03, 2014
<pre><code class="language-php">//init of context XML or JSON $contextSwitch = $this-&gt;_helper-&gt;getHelper('contextSwitch'); $contextSwitch-&gt;setContext('xml', array( 'suffix' =&gt; 'xml', 'headers' =&gt; array('Content-Type: text/xml; charset=UTF-8') )) -&gt;setContext('json', array( 'suffix' =&gt; 'json', 'headers' =&gt; array('Content-type: application/json') )) -&gt;setAutoJsonSerialization(false) -&gt;setAutoDisableLayout(true) -&gt;addActionContext($this-&gt;actionName, array('xml','json'));</code></pre><p>Then, create your views with suffix. E.g : index.json.tpl and index.xml.tpl</p>
comments powered by Disqus