<?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>Chris Danielson&#039;s Blog &#187; Zend</title>
	<atom:link href="http://www.chrisdanielson.com/tag/zend/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.chrisdanielson.com</link>
	<description>Trials and Tribulations of a Software Developer</description>
	<lastBuildDate>Wed, 14 Sep 2011 00:00:51 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Zend RESTful XML Generic Functions</title>
		<link>http://www.chrisdanielson.com/2009/10/12/zend-restful-xml-generic-functions/</link>
		<comments>http://www.chrisdanielson.com/2009/10/12/zend-restful-xml-generic-functions/#comments</comments>
		<pubDate>Tue, 13 Oct 2009 02:07:58 +0000</pubDate>
		<dc:creator>Chris Danielson</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[recursive]]></category>
		<category><![CDATA[XML]]></category>
		<category><![CDATA[Zend]]></category>
		<category><![CDATA[Zend_Rest_Controller]]></category>

		<guid isPermaLink="false">http://www.chrisdanielson.com/?p=275</guid>
		<description><![CDATA[It has been argued that the Zend RESTful API should not only automate the JSON data returned (which it does a fine job of), but automate the XML data. Unfortunately, the Zend engine doesn&#8217;t do this for REST. The solution is left to the developer to implement their own strategy. In my opinion, there is [...]]]></description>
			<content:encoded><![CDATA[<p>It has been argued that the Zend RESTful API should not only automate the JSON data returned (which it does a fine job of), but automate the XML data.  Unfortunately, the Zend engine doesn&#8217;t do this for REST.  The solution is left to the developer to implement their own strategy.  In my opinion, there is no better place for a simple recursive function that will dynamically crawl the returned objects and arrays and generate XML in a way that just makes sense.  As was promised in a comment from one of my <a href="http://www.chrisdanielson.com/2009/09/02/creating-a-php-rest-api-using-the-zend-framework/">previous blogs</a>, here is a set of functions that works well for dynamically generating XML from your PHP objects and arrays.  It&#8217;s been pointed out that this process should have been included in the Zend framework.  As of this writing, I believe that it still has not been implemented.  Anyways, here it is.  <em>Take note that you really only need two functions from this post getXML(&#8230;) and _xmlHelper(&#8230;)</em></p>

<div class="wp_codebox_msgheader"><span class="right"></span><span class="left2">Download <a href="http://www.chrisdanielson.com/wp-content/plugins/wp-codebox/wp-codebox.php?p=275&amp;download=BaseController.php">BaseController.php</a></span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p2754"><td class="code" id="p275code4"><pre class="php" style="font-family:monospace;">abstract <span style="color: #000000; font-weight: bold;">class</span> BaseController <span style="color: #000000; font-weight: bold;">extends</span> Zend_Rest_Controller
<span style="color: #009900;">&#123;</span>
<span style="color: #666666; font-style: italic;">//Please know that the init() method has been snipped out.	</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> static <span style="color: #000000; font-weight: bold;">function</span> getXML<span style="color: #009900;">&#40;</span><span style="color: #000088;">$obj</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
    	<span style="color: #000088;">$doc</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> DOMDocument<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$doc</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">formatOutput</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$root_element</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$doc</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">createElement</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;response&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$doc</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">appendChild</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$root_element</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    	<span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$obj</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$var</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$value</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        	<span style="color: #000088;">$statusElement</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$doc</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">createElement</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$var</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><a href="http://www.php.net/is_array"><span style="color: #990000;">is_array</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$value</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
				<span style="color: #000088;">$statusElement</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">appendChild</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$doc</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">createTextNode</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$value</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				<span style="color: #000088;">$root_element</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">appendChild</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$statusElement</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
				BaseController<span style="color: #339933;">::</span>_xmlHelper<span style="color: #009900;">&#40;</span><span style="color: #339933;">&amp;</span><span style="color: #000088;">$doc</span><span style="color: #339933;">,</span> <span style="color: #339933;">&amp;</span><span style="color: #000088;">$root_element</span><span style="color: #339933;">,</span> <span style="color: #339933;">&amp;</span><span style="color: #000088;">$statusElement</span><span style="color: #339933;">,</span> <span style="color: #339933;">&amp;</span><span style="color: #000088;">$value</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span>
		<span style="color: #009900;">&#125;</span>
		<span style="color: #b1b100;">print</span> <span style="color: #000088;">$doc</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">saveXML</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
	<span style="color: #000000; font-weight: bold;">public</span> static <span style="color: #000000; font-weight: bold;">function</span> _xmlHelper<span style="color: #009900;">&#40;</span><span style="color: #339933;">&amp;</span><span style="color: #000088;">$doc</span><span style="color: #339933;">,</span> <span style="color: #339933;">&amp;</span><span style="color: #000088;">$root_element</span><span style="color: #339933;">,</span> <span style="color: #339933;">&amp;</span><span style="color: #000088;">$statusElement</span><span style="color: #339933;">,</span> <span style="color: #339933;">&amp;</span><span style="color: #000088;">$value</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><a href="http://www.php.net/is_array"><span style="color: #990000;">is_array</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$value</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$value</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$key</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$val</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
				<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><a href="http://www.php.net/is_array"><span style="color: #990000;">is_array</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$val</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
					BaseController<span style="color: #339933;">::</span>_xmlHelper<span style="color: #009900;">&#40;</span><span style="color: #339933;">&amp;</span><span style="color: #000088;">$doc</span><span style="color: #339933;">,</span> <span style="color: #339933;">&amp;</span><span style="color: #000088;">$root_element</span><span style="color: #339933;">,</span> <span style="color: #339933;">&amp;</span><span style="color: #000088;">$statusElement</span><span style="color: #339933;">,</span> <span style="color: #000088;">$val</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><a href="http://www.php.net/is_object"><span style="color: #990000;">is_object</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$val</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
					<span style="color: #000088;">$se</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$doc</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">createElement</span><span style="color: #009900;">&#40;</span><a href="http://www.php.net/str_replace"><span style="color: #990000;">str_replace</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'object'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">''</span><span style="color: #339933;">,</span><a href="http://www.php.net/get_class"><span style="color: #990000;">get_class</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$val</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
					<span style="color: #000088;">$arr</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/get_object_vars"><span style="color: #990000;">get_object_vars</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$val</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
					BaseController<span style="color: #339933;">::</span>_xmlHelper<span style="color: #009900;">&#40;</span><span style="color: #339933;">&amp;</span><span style="color: #000088;">$doc</span><span style="color: #339933;">,</span> <span style="color: #339933;">&amp;</span><span style="color: #000088;">$root_element</span><span style="color: #339933;">,</span> <span style="color: #339933;">&amp;</span><span style="color: #000088;">$se</span><span style="color: #339933;">,</span> <span style="color: #000088;">$arr</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
					<span style="color: #000088;">$root_element</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">appendChild</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$se</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
				<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
					<span style="color: #666666; font-style: italic;">//print $key . &quot; =&gt; &quot; . $val . &quot;\n&quot;;</span>
					<span style="color: #000088;">$se</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$doc</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">createElement</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$key</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
					<span style="color: #000088;">$se</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">appendChild</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$doc</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">createTextNode</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$val</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
					<span style="color: #000088;">$statusElement</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">appendChild</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$se</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				<span style="color: #009900;">&#125;</span>
			<span style="color: #009900;">&#125;</span>
			<span style="color: #666666; font-style: italic;">//print_r($value);</span>
		<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #000088;">$statusElement</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">appendChild</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$doc</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">createTextNode</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$value</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #000088;">$root_element</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">appendChild</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$statusElement</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Now the only thing left to do is show an example implementation.</p>

<div class="wp_codebox_msgheader"><span class="right"></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p275code5'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p2755"><td class="code" id="p275code5"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">class</span> VersionController <span style="color: #000000; font-weight: bold;">extends</span> BaseController 
<span style="color: #009900;">&#123;</span> 
<span style="color: #666666; font-style: italic;">/*  implement the methods as show in the blog referenced at the top of this blog post */</span>
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> init<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
       <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">view</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">hello</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'a'</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'1'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'b'</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'2'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Now, the last thing to do is edit the view for the XML document which would be in this case:</p>
<pre>
/application/views/scripts/version/index.xml.phtml
</pre>
<p>The index.xml.phtml should then only contain:</p>

<div class="wp_codebox_msgheader"><span class="right"></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p275code6'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p2756"><td class="code" id="p275code6"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
BaseController<span style="color: #339933;">::</span><span style="color: #004000;">getXML</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>This will automate the process of generating the XML data you want returned.  It&#8217;s an easy way to quickly and effectively get XML without having to rebuild the entire wheel.  Feel free to modify and distribute.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.chrisdanielson.com/2009/10/12/zend-restful-xml-generic-functions/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Creating a PHP REST API Using the Zend Framework</title>
		<link>http://www.chrisdanielson.com/2009/09/02/creating-a-php-rest-api-using-the-zend-framework/</link>
		<comments>http://www.chrisdanielson.com/2009/09/02/creating-a-php-rest-api-using-the-zend-framework/#comments</comments>
		<pubDate>Wed, 02 Sep 2009 16:07:34 +0000</pubDate>
		<dc:creator>Chris Danielson</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[ContextSwitch]]></category>
		<category><![CDATA[JSON]]></category>
		<category><![CDATA[REST]]></category>
		<category><![CDATA[REST Server]]></category>
		<category><![CDATA[XML]]></category>
		<category><![CDATA[Zend]]></category>
		<category><![CDATA[Zend_Rest_Controller]]></category>

		<guid isPermaLink="false">http://www.chrisdanielson.com/?p=219</guid>
		<description><![CDATA[I don&#8217;t know about you, but I spent hours pouring over the Zend documentation and searching the Internet for some sort of understanding or example regarding how to do REST the correct way in PHP.  I found a handful of one-offs, where everyone was writing their own core REST engine from scratch. I figure why [...]]]></description>
			<content:encoded><![CDATA[<p>I don&#8217;t know about you, but I spent hours pouring over the Zend documentation and searching the Internet for some sort of understanding or example regarding how to do REST the correct way in PHP.  I found a handful of one-offs, where everyone was writing their own core REST engine from scratch.  I figure why write all the code to handle this, if you already have the Zend Framework in your code base.   I believe that the ideal solution will effectively use the the Zend_Rest_Controller and ContextSwitch objects as well as offering JSON and XML formatting options.  My goal here is simple. I want to give you the building blocks to aid in writing an easily maintainable REST API in PHP using the Zend Framework.  </p>
<p>This code example will support REST data in the format of <strong>XML </strong>and <strong>JSON</strong>.</p>
<p>Prerequisites:</p>
<ol>
<li>PHP version &gt; 5</li>
<li><a href="http://framework.zend.com/releases/ZendFramework-1.9.2/ZendFramework-1.9.2.zip">Zend Framework 1.9.2</a> (at the minimum) The generic download page can found <a href="http://framework.zend.com/download/latest">here</a>.</li>
</ol>
<p><a href="http://www.chrisdanielson.com/wp-content/uploads/2009/09/ZendRestExample.zip">Download ZendRestExample Source</a>.  You will want to download this example in order to effectively run and better understand the project.  Make sure to rename the 1.htaccess file to .htaccess (if interested in using it).  As well, take note that there are other files not listed below that are required to run this project.  These are contained within the zip&#8217;d source code.  Finally, the Zend framework is not zip&#8217;d into the source code.  You&#8217;ll need to download this and install it on your own.</p>
<p>Basic Directory Structure:</p>
<pre>
/
/.htaccess
/index.php
/applications/
/applications/configs/
/applications/controllers/
/applications/forms/
/applications/layouts/
/applications/views/
/library/  (optional where the Zend folder containing the framework should reside)
</pre>
<p>URLS used in this example:</p>
<pre>

http://yourSite/version/format/xml

http://yourSite/version/format/json

//with other parameters you can do:

http://yourSite/version/format/xml/id/1234/param2/6789
</pre>
<p>One of the tricky things with REST is that the URLs need to be formatted properly.  In Apache, all you need is the mod_rewrite module enabled and a .htaccess in the root of your current web project.</p>

<div class="wp_codebox_msgheader"><span class="right"></span><span class="left2">Download <a href="http://www.chrisdanielson.com/wp-content/plugins/wp-codebox/wp-codebox.php?p=219&amp;download=.htaccess">.htaccess</a></span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p21913"><td class="code" id="p219code13"><pre class="apache" style="font-family:monospace;"><span style="color: #00007f;">SetEnv</span> APPLICATION_ENV development
&nbsp;
<span style="color: #00007f;">RewriteEngine</span> <span style="color: #0000ff;">On</span>
<span style="color: #adadad; font-style: italic;">#RewriteBase /~myUserName/myDirectory</span>
<span style="color: #00007f;">RewriteBase</span> /
<span style="color: #00007f;">RewriteCond</span> %{REQUEST_FILENAME} -s [OR]
<span style="color: #00007f;">RewriteCond</span> %{REQUEST_FILENAME} -l [OR]
<span style="color: #00007f;">RewriteCond</span> %{REQUEST_FILENAME} -d
<span style="color: #00007f;">RewriteRule</span> ^.*$ - [NC,L]
<span style="color: #00007f;">RewriteRule</span> ^.*$ index.php [NC,L]</pre></td></tr></table></div>

<p>Now that we have adjusted the .htaccess, let&#8217;s look into the application/configs/application.ini as well as the important Bootstrap.php.</p>

<div class="wp_codebox_msgheader"><span class="right"></span><span class="left2">Download <a href="http://www.chrisdanielson.com/wp-content/plugins/wp-codebox/wp-codebox.php?p=219&amp;download=application.ini">application.ini</a></span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p21914"><td class="code" id="p219code14"><pre class="php" style="font-family:monospace;"><span style="color: #009900;">&#91;</span>production<span style="color: #009900;">&#93;</span>
phpSettings<span style="color: #339933;">.</span>display_startup_errors <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span>
phpSettings<span style="color: #339933;">.</span>display_errors <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span>
bootstrap<span style="color: #339933;">.</span>path <span style="color: #339933;">=</span> APPLICATION_PATH <span style="color: #0000ff;">&quot;/Bootstrap.php&quot;</span>
resources<span style="color: #339933;">.</span>frontController<span style="color: #339933;">.</span>controllerDirectory <span style="color: #339933;">=</span> APPLICATION_PATH <span style="color: #0000ff;">&quot;/controllers&quot;</span>
bootstrap<span style="color: #339933;">.</span><span style="color: #000000; font-weight: bold;">class</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;Bootstrap&quot;</span>
&nbsp;
<span style="color: #009900;">&#91;</span>staging <span style="color: #339933;">:</span> production<span style="color: #009900;">&#93;</span>
&nbsp;
<span style="color: #009900;">&#91;</span>testing <span style="color: #339933;">:</span> production<span style="color: #009900;">&#93;</span>
phpSettings<span style="color: #339933;">.</span>display_startup_errors <span style="color: #339933;">=</span> <span style="color: #cc66cc;">1</span>
phpSettings<span style="color: #339933;">.</span>display_errors <span style="color: #339933;">=</span> <span style="color: #cc66cc;">1</span>
&nbsp;
<span style="color: #009900;">&#91;</span>development <span style="color: #339933;">:</span> production<span style="color: #009900;">&#93;</span>
phpSettings<span style="color: #339933;">.</span>display_startup_errors <span style="color: #339933;">=</span> <span style="color: #cc66cc;">1</span>
phpSettings<span style="color: #339933;">.</span>display_errors <span style="color: #339933;">=</span> <span style="color: #cc66cc;">1</span></pre></td></tr></table></div>

<p>The core kick-start of this whole REST application is contained in the applications/Bootstrap.php</p>

<div class="wp_codebox_msgheader"><span class="right"></span><span class="left2">Download <a href="http://www.chrisdanielson.com/wp-content/plugins/wp-codebox/wp-codebox.php?p=219&amp;download=Bootstrap.php">Bootstrap.php</a></span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p21915"><td class="code" id="p219code15"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">class</span> Bootstrap <span style="color: #000000; font-weight: bold;">extends</span> Zend_Application_Bootstrap_Bootstrap
<span style="color: #009900;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000000; font-weight: bold;">function</span> _initAutoload<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$autoloader</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Zend_Application_Module_Autoloader<span style="color: #009900;">&#40;</span><a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span>
            <span style="color: #0000ff;">'namespace'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'Default_'</span><span style="color: #339933;">,</span>
            <span style="color: #0000ff;">'basePath'</span>  <span style="color: #339933;">=&gt;</span> <a href="http://www.php.net/dirname"><span style="color: #990000;">dirname</span></a><span style="color: #009900;">&#40;</span><span style="color: #009900; font-weight: bold;">__FILE__</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
        <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #b1b100;">return</span> <span style="color: #000088;">$autoloader</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span> 
&nbsp;
	<span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000000; font-weight: bold;">function</span> _initRestRoute<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">bootstrap</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Request'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>	
		<span style="color: #000088;">$front</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getResource</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'FrontController'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$restRoute</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Zend_Rest_Route<span style="color: #009900;">&#40;</span><span style="color: #000088;">$front</span><span style="color: #339933;">,</span> <a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span>
			<span style="color: #0000ff;">'default'</span> <span style="color: #339933;">=&gt;</span> <a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'version'</span><span style="color: #009900;">&#41;</span>
		<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$front</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getRouter</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">addRoute</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'rest'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$restRoute</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span> 
&nbsp;
	<span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000000; font-weight: bold;">function</span> _initRequest<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">bootstrap</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'FrontController'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$front</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getResource</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'FrontController'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$request</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$front</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getRequest</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #009900; font-weight: bold;">null</span> <span style="color: #339933;">===</span> <span style="color: #000088;">$front</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getRequest</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000088;">$request</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Zend_Controller_Request_Http<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #000088;">$front</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setRequest</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$request</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
    	<span style="color: #b1b100;">return</span> <span style="color: #000088;">$request</span><span style="color: #339933;">;</span>        
    <span style="color: #009900;">&#125;</span> 		
&nbsp;
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Now we need to wire up the ability for web requests to move through this engine.  We do this in our /index.php file.</p>

<div class="wp_codebox_msgheader"><span class="right"></span><span class="left2">Download <a href="http://www.chrisdanielson.com/wp-content/plugins/wp-codebox/wp-codebox.php?p=219&amp;download=index.php">index.php</a></span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p21916"><td class="code" id="p219code16"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #666666; font-style: italic;">// Define path to application directory</span>
<a href="http://www.php.net/defined"><span style="color: #990000;">defined</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'APPLICATION_PATH'</span><span style="color: #009900;">&#41;</span>
    <span style="color: #339933;">||</span> <a href="http://www.php.net/define"><span style="color: #990000;">define</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'APPLICATION_PATH'</span><span style="color: #339933;">,</span> <a href="http://www.php.net/realpath"><span style="color: #990000;">realpath</span></a><span style="color: #009900;">&#40;</span><a href="http://www.php.net/dirname"><span style="color: #990000;">dirname</span></a><span style="color: #009900;">&#40;</span><span style="color: #009900; font-weight: bold;">__FILE__</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'/application'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Define application environment</span>
<a href="http://www.php.net/defined"><span style="color: #990000;">defined</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'APPLICATION_ENV'</span><span style="color: #009900;">&#41;</span>
    <span style="color: #339933;">||</span> <a href="http://www.php.net/define"><span style="color: #990000;">define</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'APPLICATION_ENV'</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#40;</span><a href="http://www.php.net/getenv"><span style="color: #990000;">getenv</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'APPLICATION_ENV'</span><span style="color: #009900;">&#41;</span> ? <a href="http://www.php.net/getenv"><span style="color: #990000;">getenv</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'APPLICATION_ENV'</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">:</span> <span style="color: #0000ff;">'production'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Ensure library/ is on include_path</span>
<span style="color: #666666; font-style: italic;">/*
If you do not have the Zend library already included in your PHP installation...
&nbsp;
1.  Create a directory named library and place the Zend Framework into it.
&nbsp;
NOTE: In my instance, I have the Zend library residing under /usr/share/php/   
Because of this, the following lines are commented.
*/</span>
<span style="color: #666666; font-style: italic;">/*set_include_path(implode(PATH_SEPARATOR, array(
    realpath(APPLICATION_PATH . '/library'),
    get_include_path(),
)));
*/</span>
&nbsp;
<span style="color: #009933; font-style: italic;">/** Zend_Application */</span>
<span style="color: #b1b100;">require_once</span> <span style="color: #0000ff;">'Zend/Application.php'</span><span style="color: #339933;">;</span> 
&nbsp;
<span style="color: #666666; font-style: italic;">// Create application, bootstrap, and run</span>
<span style="color: #000088;">$application</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Zend_Application<span style="color: #009900;">&#40;</span>
    APPLICATION_ENV<span style="color: #339933;">,</span> 
    APPLICATION_PATH <span style="color: #339933;">.</span> <span style="color: #0000ff;">'/configs/application.ini'</span>
<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$application</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">bootstrap</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">run</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>Well now that the core is in place, all we need is to integrate our controllers.  This is where our business logic will reside.</p>

<div class="wp_codebox_msgheader"><span class="right"></span><span class="left2">Download <a href="http://www.chrisdanielson.com/wp-content/plugins/wp-codebox/wp-codebox.php?p=219&amp;download=VersionController.php">VersionController.php</a></span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p21917"><td class="code" id="p219code17"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">class</span> VersionController <span style="color: #000000; font-weight: bold;">extends</span> Zend_Rest_Controller
<span style="color: #009900;">&#123;</span>  
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> init<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$bootstrap</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getInvokeArg</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'bootstrap'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #000088;">$options</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$bootstrap</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getOption</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'resources'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #000088;">$contextSwitch</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_helper<span style="color: #339933;">-&gt;</span><span style="color: #004000;">getHelper</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'contextSwitch'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$contextSwitch</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">addActionContext</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'index'</span><span style="color: #339933;">,</span> <a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'xml'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'json'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">initContext</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #666666; font-style: italic;">//$this-&gt;_helper-&gt;viewRenderer-&gt;setNeverRender();	</span>
		<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">view</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">success</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;true&quot;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">view</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">version</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;1.0&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #009933; font-style: italic;">/**
     * The index action handles index/list requests; it should respond with a
     * list of the requested resources.
     */</span> 
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> indexAction<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
		<span style="color: #666666; font-style: italic;">//if you want to have access to a particular paramater use the helper function as follows:</span>
		<span style="color: #666666; font-style: italic;">//print $this-&gt;_helper-&gt;getParam('abc');</span>
               <span style="color: #666666; font-style: italic;">//To test with this use:  http://myURL/format/xml/abc/1002</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> listAction<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_forward<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'index'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> getAction<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_forward<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'index'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> newAction<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>   	
		<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_forward<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'index'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> postAction<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_forward<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'index'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> editAction<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>    	 
		<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_forward<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'index'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> putAction<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_forward<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'index'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span> 
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> deleteAction<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_forward<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'index'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Now that we&#8217;ve done this, the URL for format of JSON just works as-is thanks to the Zend ContextSwitch engine.  No other changes are needed.  If you are interested in having the output in XML format, then you&#8217;ll need to make a few additions.  Now that we&#8217;ve taken care of the Controller, we&#8217;re going to have to add in the views to make the XML work with the ContextSwitch.  So under /applications/views/scripts/version/  you&#8217;ll need a file:  index.xml.phtml</p>

<div class="wp_codebox_msgheader"><span class="right"></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p219code18'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p21918"><td class="code" id="p219code18"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #000088;">$doc</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> DOMDocument<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$doc</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">formatOutput</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$root_element</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$doc</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">createElement</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;response&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$doc</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">appendChild</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$root_element</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$statusElement</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$doc</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">createElement</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;success&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$statusElement</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">appendChild</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$doc</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">createTextNode</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">success</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$root_element</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">appendChild</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$statusElement</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$versionElement</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$doc</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">createElement</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;version&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$versionElement</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">appendChild</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$doc</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">createTextNode</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">version</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$root_element</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">appendChild</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$versionElement</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">print</span> <span style="color: #000088;">$doc</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">saveXML</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>And that is all there is to it.  We&#8217;ve now made a basic index/list REST API for listing the version of your product.  This is an overly simple example of how to integrate quickly the Zend REST engine.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.chrisdanielson.com/2009/09/02/creating-a-php-rest-api-using-the-zend-framework/feed/</wfw:commentRss>
		<slash:comments>24</slash:comments>
		</item>
	</channel>
</rss>

