<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>clear solution &#8211; stoimen&#039;s web log</title>
	<atom:link href="/tag/clear-solution/feed/" rel="self" type="application/rss+xml" />
	<link></link>
	<description>on web development</description>
	<lastBuildDate>Tue, 13 Feb 2018 08:18:15 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>https://wordpress.org/?v=5.0.3</generator>
	<item>
		<title>Returning JSON in a Zend Controller&#8217;s Action</title>
		<link>/2010/08/13/returning-json-in-a-zend-controllers-action/</link>
		<comments>/2010/08/13/returning-json-in-a-zend-controllers-action/#comments</comments>
		<pubDate>Fri, 13 Aug 2010 13:14:26 +0000</pubDate>
		<dc:creator><![CDATA[Stoimen]]></dc:creator>
				<category><![CDATA[micro tutorial]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[zend framework]]></category>
		<category><![CDATA[ajax]]></category>
		<category><![CDATA[clear solution]]></category>
		<category><![CDATA[Computing]]></category>
		<category><![CDATA[encode()]]></category>
		<category><![CDATA[JavaScript programming language]]></category>
		<category><![CDATA[JSON]]></category>
		<category><![CDATA[JSON-RPC]]></category>
		<category><![CDATA[Markup languages]]></category>
		<category><![CDATA[Software engineering]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[zend_json]]></category>

		<guid isPermaLink="false">/?p=1905</guid>
		<description><![CDATA[There are three basic ways that you can achieve that. First of all what&#8217;s the task? You&#8217;ve an array, either from a database result or whatever, and you encode it JSON with Zend_Json::encode($array) // IndexController.php class IndexController extends Zend_Controller_Action { public function indexAction() { $data = array(...); $this->view->data = Zend_Json::encode($data); } } The result in &#8230; <a href="/2010/08/13/returning-json-in-a-zend-controllers-action/" class="more-link">Continue reading <span class="screen-reader-text">Returning JSON in a Zend Controller&#8217;s Action</span> <span class="meta-nav">&#8594;</span></a><div class='yarpp-related-rss'>

Related posts:<ol>
<li><a href="/2010/08/19/returning-json-in-a-zend-controller%e2%80%99s-action-part-2/" rel="bookmark" title="Returning JSON in a Zend Controller’s Action &#8211; Part 2">Returning JSON in a Zend Controller’s Action &#8211; Part 2 </a></li>
<li><a href="/2010/06/10/json-and-zend-framework-zend_json/" rel="bookmark" title="JSON and Zend Framework? &#8211; Zend_Json">JSON and Zend Framework? &#8211; Zend_Json </a></li>
<li><a href="/2010/06/07/bind-zend-action-with-non-default-view/" rel="bookmark" title="Bind Zend Action with Non-Default View">Bind Zend Action with Non-Default View </a></li>
<li><a href="/2010/06/24/zend-framework-inject-javascript-code-in-a-actionview/" rel="bookmark" title="Zend Framework: Inject JavaScript Code in a Action/View">Zend Framework: Inject JavaScript Code in a Action/View </a></li>
</ol>
</div>
]]></description>
				<content:encoded><![CDATA[<p>There are three basic ways that you can achieve that. First of all what&#8217;s the task? You&#8217;ve an array, either from a database result or whatever, and you encode it JSON with Zend_Json::encode($array)</p>
<pre lang="php">
// IndexController.php
class IndexController extends Zend_Controller_Action
{
	public function indexAction()
	{
		$data = array(...);
		
		$this->view->data = Zend_Json::encode($data);	
	}	
}
</pre>
<p>The result in general is a specially formatted string. So you can simply set it up to a view member variable and pass it to the view.</p>
<pre lang="php">
// index/index.phtml
echo $this->data
</pre>
<p>In that case you&#8217;ve a .phtml file to maintain, so lets just return the string and &#8220;setNoRender&#8221; the view in our second try.</p>
<pre lang="php">
// IndexController.php
class IndexController extends Zend_Controller_Action
{
	public function indexAction()
	{
		$data = array(...);
		
		echo Zend_Json::encode($data);	
		
		$this->_helper->viewRenderer->setNoRender(true);
	}	
}
</pre>
<p>Actually this is pretty much the most clear solution, but actually you can output the JSON string and simply exit() as it&#8217;s shown in our third example.</p>
<pre lang="php">
// IndexController.php
class IndexController extends Zend_Controller_Action
{
	public function indexAction()
	{
		$data = array(...);
		
		echo Zend_Json::encode($data);	
		
		exit();
	}	
}
</pre>
<p>Which one is to be used is up to the developer&#8217;s choice, mine is the third one as it&#8217;s the minimal one.</p>
<div class='yarpp-related-rss'>
<p>Related posts:<ol>
<li><a href="/2010/08/19/returning-json-in-a-zend-controller%e2%80%99s-action-part-2/" rel="bookmark" title="Returning JSON in a Zend Controller’s Action &#8211; Part 2">Returning JSON in a Zend Controller’s Action &#8211; Part 2 </a></li>
<li><a href="/2010/06/10/json-and-zend-framework-zend_json/" rel="bookmark" title="JSON and Zend Framework? &#8211; Zend_Json">JSON and Zend Framework? &#8211; Zend_Json </a></li>
<li><a href="/2010/06/07/bind-zend-action-with-non-default-view/" rel="bookmark" title="Bind Zend Action with Non-Default View">Bind Zend Action with Non-Default View </a></li>
<li><a href="/2010/06/24/zend-framework-inject-javascript-code-in-a-actionview/" rel="bookmark" title="Zend Framework: Inject JavaScript Code in a Action/View">Zend Framework: Inject JavaScript Code in a Action/View </a></li>
</ol></p>
</div>
]]></content:encoded>
			<wfw:commentRss>/2010/08/13/returning-json-in-a-zend-controllers-action/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
	</channel>
</rss>
