<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Zend on jpcercal.com</title><link>https://jpcercal.com/en/tags/zend/</link><description>Recent content in Zend on jpcercal.com</description><generator>Hugo</generator><language>en</language><lastBuildDate>Tue, 29 Nov 2011 16:54:51 +0000</lastBuildDate><atom:link href="https://jpcercal.com/en/tags/zend/index.xml" rel="self" type="application/rss+xml"/><item><title>Zend disable the layout and view renderer</title><link>https://jpcercal.com/en/zend-disable-the-layout-and-view-renderer/</link><pubDate>Tue, 29 Nov 2011 16:54:51 +0000</pubDate><guid>https://jpcercal.com/en/zend-disable-the-layout-and-view-renderer/</guid><description>&lt;p&gt;Some people have been asking me how to disable the layout and view renderer in&#10;&lt;strong&gt;Zend Framework&lt;/strong&gt; so an &lt;em&gt;action&lt;/em&gt; in a given &lt;em&gt;controller&lt;/em&gt; returns only &lt;strong&gt;JSON&lt;/strong&gt;.&#10;Well, to do this, just use two lines of code, as you can see below.&lt;/p&gt;&#10;&lt;p&gt;This first approach disables the layout and view renderer for all &lt;em&gt;actions&lt;/em&gt; in a given&#10;&lt;em&gt;controller&lt;/em&gt;:&lt;/p&gt;&#10;&lt;div class="highlight"&gt;&lt;div class="chroma"&gt;&#10;&lt;table class="lntable"&gt;&lt;tr&gt;&lt;td class="lntd"&gt;&#10;&lt;pre tabindex="0" class="chroma"&gt;&lt;code&gt;&lt;span class="lnt"&gt;1&#10;&lt;/span&gt;&lt;span class="lnt"&gt;2&#10;&lt;/span&gt;&lt;span class="lnt"&gt;3&#10;&lt;/span&gt;&lt;span class="lnt"&gt;4&#10;&lt;/span&gt;&lt;span class="lnt"&gt;5&#10;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&#10;&lt;td class="lntd"&gt;&#10;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-php" data-lang="php"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;preDispatch&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="p"&gt;{&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="nv"&gt;$this&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="na"&gt;_helper&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="na"&gt;layout&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="na"&gt;disableLayout&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="nv"&gt;$this&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="na"&gt;_helper&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="na"&gt;viewRenderer&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="na"&gt;setNoRender&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;true&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="p"&gt;}&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&#10;&lt;/div&gt;&#10;&lt;/div&gt;&lt;p&gt;However, this second approach disables the layout and view renderer for only one &lt;em&gt;action&lt;/em&gt;,&#10;in this case &lt;em&gt;&amp;ldquo;index&amp;rdquo;&lt;/em&gt;:&lt;/p&gt;</description></item></channel></rss>