<?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>source code bean</title>
	<atom:link href="http://sourcecodebean.com/feed" rel="self" type="application/rss+xml" />
	<link>http://sourcecodebean.com</link>
	<description>giving you tricks and tips of good coding</description>
	<lastBuildDate>Mon, 08 Mar 2010 06:05:59 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Trying out CouchDB for the first time</title>
		<link>http://sourcecodebean.com/archives/trying-out-couchdb-for-the-first-time/480</link>
		<comments>http://sourcecodebean.com/archives/trying-out-couchdb-for-the-first-time/480#comments</comments>
		<pubDate>Mon, 08 Mar 2010 06:05:59 +0000</pubDate>
		<dc:creator>Peter</dc:creator>
				<category><![CDATA[NoSQL]]></category>

		<guid isPermaLink="false">http://sourcecodebean.com/?p=480</guid>
		<description><![CDATA[There are several good libraries that will abstract accessing CouchDB. However, in order to understand what goes on in the libraries, I think it is important to first understand what is going on on a lower lever, so that is what I will show you. 
Step 1, install CouchDB. CouchDB for OSX can be downloaded [...]]]></description>
			<content:encoded><![CDATA[<p>There are several good libraries that will abstract accessing CouchDB. However, in order to understand what goes on in the libraries, I think it is important to first understand what is going on on a lower lever, so that is what I will show you. </p>
<p>Step 1, install CouchDB. CouchDB for OSX can be downloaded <a href="http://janl.github.com/couchdbx/">here</a>, the bundle contains bouth the Erlang runtime and CouchDB &#8211; no compiling or installing needed, just download the .dmg, mount it and run the application! If you are on Linux it is quite likely that CouchDB is in the repository of your distribution. In Ubuntu CouchDB is found in &#8220;Universe&#8221; and can easily be installed using apt. I haven&#8217;t tried CouchDB on Windows so I can&#8217;t give you any guidance here, if you try it out, please leave a comment. </p>
<p> Now when CouchDB is installed lets explore it using use one of my favorite tools, good old cURL. Port 5984 is the default port for CouchDB. </p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">$ curl -X GET http:<span class="co1">//localhost:5984/</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#123;</span><span class="st0">&quot;couchdb&quot;</span>:<span class="st0">&quot;Welcome&quot;</span>,<span class="st0">&quot;version&quot;</span>:<span class="st0">&quot;0.10.0&quot;</span><span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
</ol>
</div>
<p>CouchDB is up running! Lets create a new database:</p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">$ curl -X PUT http:<span class="co1">//localhost:5984/testdb</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#123;</span><span class="st0">&quot;ok&quot;</span>:<span class="kw2">true</span><span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
</ol>
</div>
<p>CouchDB&#8217;s responses are also in JSON form. Lets inspect the database we just created:</p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">$ curl -X GET http:<span class="co1">//localhost:5984/testdb</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="st0">&quot;db_name&quot;</span>:<span class="st0">&quot;testdb&quot;</span>,</div>
</li>
<li class="li2">
<div class="de2">&nbsp; <span class="st0">&quot;doc_count&quot;</span>:<span class="nu0">0</span>,</div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="st0">&quot;doc_del_count&quot;</span>:<span class="nu0">0</span>,</div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="st0">&quot;update_seq&quot;</span>:<span class="nu0">0</span>,</div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="st0">&quot;purge_seq&quot;</span>:<span class="nu0">0</span>,</div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="st0">&quot;compact_running&quot;</span>:<span class="kw2">false</span>,</div>
</li>
<li class="li2">
<div class="de2">&nbsp; <span class="st0">&quot;disk_size&quot;</span>:<span class="nu0">79</span>,</div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="st0">&quot;instance_start_time&quot;</span>:<span class="st0">&quot;1266963717052501&quot;</span>,</div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="st0">&quot;disk_format_version&quot;</span>:<span class="nu0">4</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
</ol>
</div>
<p>CouchDB returns some statistics of the database, we can see that it contains 0 documents. Lets store an empty document in the database:</p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">$ curl -X POST http:<span class="co1">//localhost:5984/testdb/ -H &quot;Content-Type: application/json&quot; -d {}</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="st0">&quot;ok&quot;</span>:<span class="kw2">true</span>,</div>
</li>
<li class="li2">
<div class="de2">&nbsp; <span class="st0">&quot;id&quot;</span>:<span class="st0">&quot;ef40feff87010a6ef3a45a16df5af977&quot;</span>,</div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="st0">&quot;rev&quot;</span>:<span class="st0">&quot;1-967a00dff5e02add41819138abb3284d&quot;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
</ol>
</div>
<p>CouchDB returns the unique id for the document and the version number (did i mention that all documents are version controlled?:)). Next step is to fetch all documents:</p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">$ curl -X GET http:<span class="co1">//localhost:5984/testdb/_all_docs</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="st0">&quot;total_rows&quot;</span>:<span class="nu0">1</span>,</div>
</li>
<li class="li2">
<div class="de2">&nbsp; <span class="st0">&quot;offset&quot;</span>:<span class="nu0">0</span>,</div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="st0">&quot;rows&quot;</span>:<span class="br0">&#91;</span><span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="st0">&quot;id&quot;</span>:<span class="st0">&quot;ef40feff87010a6ef3a45a16df5af977&quot;</span>,</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="st0">&quot;key&quot;</span>:<span class="st0">&quot;ef40feff87010a6ef3a45a16df5af977&quot;</span>,</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="st0">&quot;value&quot;</span>:<span class="br0">&#123;</span><span class="st0">&quot;rev&quot;</span>:<span class="st0">&quot;1-967a00dff5e02add41819138abb3284d&quot;</span><span class="br0">&#125;</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; <span class="br0">&#125;</span><span class="br0">&#93;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
</ol>
</div>
<p>Yes! it is there! Now you should also be able to see your database &#8220;testdb&#8221; and the document you created in the CouchDB GUI.</p>
]]></content:encoded>
			<wfw:commentRss>http://sourcecodebean.com/archives/trying-out-couchdb-for-the-first-time/480/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>CouchDB a NoSQL database</title>
		<link>http://sourcecodebean.com/archives/couchdb-a-nosql-database/460</link>
		<comments>http://sourcecodebean.com/archives/couchdb-a-nosql-database/460#comments</comments>
		<pubDate>Mon, 01 Mar 2010 20:44:29 +0000</pubDate>
		<dc:creator>Peter</dc:creator>
				<category><![CDATA[NoSQL]]></category>

		<guid isPermaLink="false">http://sourcecodebean.com/?p=460</guid>
		<description><![CDATA[Traditionally relational databases has been the primary way of storing, sorting and searching data, and for most purposes they are very good at it. However, in the last few years &#8211; with the growth of cloud computing and sites such as Facebook pushing relational databases to its limits, people have started to look for other [...]]]></description>
			<content:encoded><![CDATA[<p>Traditionally relational databases has been the primary way of storing, sorting and searching data, and for most purposes they are very good at it. However, in the last few years &#8211; with the growth of cloud computing and sites such as Facebook pushing relational databases to its limits, people have started to look for other alternatives. The problems with relational databases is that it has been hard to scale them in a vertical way (scale them over several servers with linear, or close to linear, performance increase). A few databases in a cluster is no problem, but when it comes to several terabytes of data, which should be searched in real time, they are simply not enough. CouchDB and the other NoSQL databases aims to provide a truly horizontally scalable database.</p>
<p>NoSQL is a umbrella term for a wide variety of data stores, which all have in common that they do not store data in a relational way. Some examples of NoSQL databases are CouchDB, MongoDB, Amazon SimpleDB and Google BigTable. This is some of the properties they have in common:</p>
<p><strong>1. No schema</strong><br />
The data is stored in one big hashtable like data structure. No schema is needed. </p>
<p><strong>2. No more joins</strong><br />
Joins are slow in general, when they are spread out over several servers it gets even worse. In CouchDB there is no join, instead data should be duplicated. This might sound odd if you like me was taucht back in collage that normalization is of highest importance, and that you should really really avoid to duplicate data in your database. This is still true for most relational databases, but keep in mind that when relational databases was invented, disk space was expensive and normalization was a great way to save a few bytes. Storage is everything but expensive today, this is why NoSQL empathizes that data should instead be duplicated. </p>
<p><strong>3. Eventual consistency</strong><br />
When you update the database there is no longer a quarantine that all subsequent queries will get the updated value immediately, it might take some time depending on the system load. For some systems such as banking systems, this kind of behavior would be a big no no. But for most large web sites, this is no problem, the data is going to be cached in one way or another anyway. </p>
<p><br/></p>
<h2>CouchDB</h2>
<p>CouchDB is a document database, accessible via a RESTful JSON API. Everything stored in the database is a &#8220;document&#8221; and is stored in a flat address space.There are no schemas, the documents are stored and retrieved as JSON objects.</p>
<p>To address this problem of adding structure back to semi-structured data, CouchDB has something called &#8220;views&#8221;. A view is as close as we gets to a SQL query. The views are expressed in Javascript and consist of map and filter functions. They are built dynamically and will not affect the underlying data.</p>
<p>CouchDB is written in Erlang and runs on all systems that the Erlang runtime supports (Linux, Windows, OSX and other unix systems). I have tested CouchDB on Linux and OSX. This is a screenshot of the CouchDBX GUI running on OSX:<br />
<a href="http://sourcecodebean.com/wp-content/uploads/2010/02/couchdb.png"><img src="http://sourcecodebean.com/wp-content/uploads/2010/02/couchdb.png" alt="" title="couchdb" width="500" height="337" class="aligncenter size-full wp-image-469" /></a></p>
<p>The JSON representation of the same document:<br />
<a href="http://sourcecodebean.com/wp-content/uploads/2010/02/couchdb2.png"><img src="http://sourcecodebean.com/wp-content/uploads/2010/02/couchdb2.png" alt="" title="couchdb2" width="500" height="388" class="aligncenter size-full wp-image-474" /></a></p>
<p>In my next post I will show you some hands on action with CouchDB.</p>
]]></content:encoded>
			<wfw:commentRss>http://sourcecodebean.com/archives/couchdb-a-nosql-database/460/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Articles coming up on CouchDB and ExtJS</title>
		<link>http://sourcecodebean.com/archives/articles-coming-up-couchdb-and-extjs/452</link>
		<comments>http://sourcecodebean.com/archives/articles-coming-up-couchdb-and-extjs/452#comments</comments>
		<pubDate>Sun, 14 Feb 2010 23:46:24 +0000</pubDate>
		<dc:creator>Peter</dc:creator>
				<category><![CDATA[ExtJS]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://sourcecodebean.com/?p=452</guid>
		<description><![CDATA[It has been a bit too long since my last post so I wanted to give you an short update on what I have been up to lately. Last year I built a web service using Amazon SimpleDB, which got me interested in document based databases. Since then I have been reading and following the [...]]]></description>
			<content:encoded><![CDATA[<p>It has been a bit too long since my last post so I wanted to give you an short update on what I have been up to lately. Last year I built a web service using Amazon SimpleDB, which got me interested in document based databases. Since then I have been reading and following the progress of different open source document based databases, such as CouchDB and MongoDB. </p>
<p>During the time, I have been thinking about what other kind of projects a document based database would be suitable for. Because my lack of imagination (or just because I was too eager to get started:)), i decided to build a simple Web CMS system using PHP and CoachDB. Pages in a CMS system are perfect for storing as documents in a document database, so it seemed like a good choice. </p>
<p>Building the CMS backend actually turned out to be what took the shortest time. I wanted to create a nice looking Javascript based GUI for the editors and administrators, and decided to build it using the javascript library ExtJS. I had never worked with ExtJS before (and I am more of a backend guy than a javascript frontend guy), so it took me some time to get my mind around it, but the result is sweet &#8211; ExtJS is really powerful. </p>
<p>The CMS is far from complete, but so far it has given me quite a few ideas for new blog posts, so stay tuned for the upcoming posts on CoachDB and ExtJS!</p>
]]></content:encoded>
			<wfw:commentRss>http://sourcecodebean.com/archives/articles-coming-up-couchdb-and-extjs/452/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Creating a JSON-RPC service using Zend Json Server</title>
		<link>http://sourcecodebean.com/archives/creating-a-json-rpc-service-using-zend-json-server/422</link>
		<comments>http://sourcecodebean.com/archives/creating-a-json-rpc-service-using-zend-json-server/422#comments</comments>
		<pubDate>Thu, 07 Jan 2010 08:11:15 +0000</pubDate>
		<dc:creator>Peter</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Web]]></category>
		<category><![CDATA[Zend Framework]]></category>

		<guid isPermaLink="false">http://sourcecodebean.com/?p=422</guid>
		<description><![CDATA[In this post I am going to show how easy it is to create a JSON-RPC web service using the built in support in Zend Framework.
First we need to create the php-file that will handle the incoming RPC calls. It is not advised to put this inside the MVC structure of a Zend web application, [...]]]></description>
			<content:encoded><![CDATA[<p>In this post I am going to show how easy it is to create a JSON-RPC web service using the built in support in Zend Framework.</p>
<p>First we need to create the php-file that will handle the incoming RPC calls. It is not advised to put this inside the MVC structure of a Zend web application, since that will lead to unessesary complexity and overhead. The Zend people recommend that we create the JSON-RPC under <code>/public/api/vX/</code>, so lets create the file <code>/public/api/v1/jsonrpc.php</code> (if you haven&#8217;t setup your Zend MVC structure, read my blog post  <a href="http://sourcecodebean.com/archives/getting-started-with-the-zend-framework/374">Getting started with the zend framework</a> to get started).</p>
<p>We will have to do the regular bootstrapping to get our application up and running:</p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="co1">// Define path to application directory</span></div>
</li>
<li class="li1">
<div class="de1"><a href="http://www.php.net/defined"><span class="kw3">defined</span></a><span class="br0">&#40;</span><span class="st0">&#8216;APPLICATION_PATH&#8217;</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; || <a href="http://www.php.net/define"><span class="kw3">define</span></a><span class="br0">&#40;</span><span class="st0">&#8216;APPLICATION_PATH&#8217;</span>, <a href="http://www.php.net/realpath"><span class="kw3">realpath</span></a><span class="br0">&#40;</span><a href="http://www.php.net/dirname"><span class="kw3">dirname</span></a><span class="br0">&#40;</span><span class="kw2">__FILE__</span><span class="br0">&#41;</span> . <span class="st0">&#8216;/../../../application&#8217;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li2">
<div class="de2">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="co1">// Define application environment</span></div>
</li>
<li class="li1">
<div class="de1"><a href="http://www.php.net/defined"><span class="kw3">defined</span></a><span class="br0">&#40;</span><span class="st0">&#8216;APPLICATION_ENV&#8217;</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; || <a href="http://www.php.net/define"><span class="kw3">define</span></a><span class="br0">&#40;</span><span class="st0">&#8216;APPLICATION_ENV&#8217;</span>, <span class="br0">&#40;</span><a href="http://www.php.net/getenv"><span class="kw3">getenv</span></a><span class="br0">&#40;</span><span class="st0">&#8216;APPLICATION_ENV&#8217;</span><span class="br0">&#41;</span> ? <a href="http://www.php.net/getenv"><span class="kw3">getenv</span></a><span class="br0">&#40;</span><span class="st0">&#8216;APPLICATION_ENV&#8217;</span><span class="br0">&#41;</span> : <span class="st0">&#8216;production&#8217;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li2">
<div class="de2"><span class="co1">// Ensure library/ is on include_path</span></div>
</li>
<li class="li1">
<div class="de1"><a href="http://www.php.net/set_include_path"><span class="kw3">set_include_path</span></a><span class="br0">&#40;</span><a href="http://www.php.net/implode"><span class="kw3">implode</span></a><span class="br0">&#40;</span>PATH_SEPARATOR, <a href="http://www.php.net/array"><span class="kw3">array</span></a><span class="br0">&#40;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <a href="http://www.php.net/realpath"><span class="kw3">realpath</span></a><span class="br0">&#40;</span><span class="st0">&#8216;../../../library&#8217;</span><span class="br0">&#41;</span>,</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <a href="http://www.php.net/get_include_path"><span class="kw3">get_include_path</span></a><span class="br0">&#40;</span><span class="br0">&#41;</span>,</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li2">
<div class="de2">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="coMULTI">/** Zend_Application */</span></div>
</li>
<li class="li1">
<div class="de1"><span class="kw1">require_once</span> <span class="st0">&#8216;Zend/Application.php&#8217;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="co1">// Create application, bootstrap, and run</span></div>
</li>
<li class="li2">
<div class="de2"><span class="re0">$application</span> = <span class="kw2">new</span> Zend_Application<span class="br0">&#40;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; APPLICATION_ENV,</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; APPLICATION_PATH . <span class="st0">&#8216;/configs/application.ini&#8217;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li2">
<div class="de2"><span class="re0">$application</span>-&gt;<span class="me1">bootstrap</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
</ol>
</div>
<p>The next step is to create the class that will be exposed through the service. I will create a very simple class that will simply perform an addition of two ints. It is very important to describe the input parameters using the @param directive in the comment. This information is used by the Json Server when creating the SMD (Service Mapping Description).</p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="coMULTI">/**</span></div>
</li>
<li class="li1">
<div class="de1"><span class="coMULTI">&nbsp;* Simple &#8211; sample class to expose via JSON-RPC</span></div>
</li>
<li class="li1">
<div class="de1"><span class="coMULTI">&nbsp;*/</span></div>
</li>
<li class="li2">
<div class="de2"><span class="kw2">class</span> Simple</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="coMULTI">/**</span></div>
</li>
<li class="li1">
<div class="de1"><span class="coMULTI">&nbsp; &nbsp; &nbsp;* Return sum of two variables</span></div>
</li>
<li class="li1">
<div class="de1"><span class="coMULTI">&nbsp; &nbsp; &nbsp;*</span></div>
</li>
<li class="li2">
<div class="de2"><span class="coMULTI">&nbsp; &nbsp; &nbsp;* @param &nbsp;int $x</span></div>
</li>
<li class="li1">
<div class="de1"><span class="coMULTI">&nbsp; &nbsp; &nbsp;* @param &nbsp;int $y</span></div>
</li>
<li class="li1">
<div class="de1"><span class="coMULTI">&nbsp; &nbsp; &nbsp;* @return array</span></div>
</li>
<li class="li1">
<div class="de1"><span class="coMULTI">&nbsp; &nbsp; &nbsp;*/</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw2">public</span> <span class="kw2">function</span> add<span class="br0">&#40;</span><span class="re0">$x</span>, <span class="re0">$y</span><span class="br0">&#41;</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">return</span> <a href="http://www.php.net/array"><span class="kw3">array</span></a><span class="br0">&#40;</span><span class="st0">&#8216;result&#8217;</span> =&gt; <span class="re0">$x</span> + <span class="re0">$y</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
</ol>
</div>
<p>The last step to get the JSON-RPC server running:</p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="co1">// Instantiate server, etc.</span></div>
</li>
<li class="li1">
<div class="de1"><span class="re0">$server</span> = <span class="kw2">new</span> Zend_Json_Server<span class="br0">&#40;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="re0">$server</span>-&gt;<span class="me1">setClass</span><span class="br0">&#40;</span><span class="st0">&#8216;Simple&#8217;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li2">
<div class="de2">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="kw1">if</span> <span class="br0">&#40;</span><span class="st0">&#8216;GET&#8217;</span> == <span class="re0">$_SERVER</span><span class="br0">&#91;</span><span class="st0">&#8216;REQUEST_METHOD&#8217;</span><span class="br0">&#93;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="co1">// Indicate the URL endpoint, and the JSON-RPC version used:</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="re0">$server</span>-&gt;<span class="me1">setTarget</span><span class="br0">&#40;</span><span class="st0">&#8216;/api/v1/jsonrpc.php&#8217;</span><span class="br0">&#41;</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;-&gt;<span class="me1">setEnvelope</span><span class="br0">&#40;</span>Zend_Json_Server_Smd::<span class="me2">ENV_JSONRPC_2</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="co1">// Grab the SMD</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="re0">$smd</span> = <span class="re0">$server</span>-&gt;<span class="me1">getServiceMap</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; <span class="co1">// Return the SMD to the client</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <a href="http://www.php.net/header"><span class="kw3">header</span></a><span class="br0">&#40;</span><span class="st0">&#8216;Content-Type: application/json&#8217;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <a href="http://www.php.net/echo"><span class="kw3">echo</span></a> <span class="re0">$smd</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw1">return</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="re0">$server</span>-&gt;<span class="me1">handle</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
</ol>
</div>
<p>Now your JSON-RPC Server should be up running. Browsing <code>http://{your web server}/api/v1/jsonrpc.php</code> should result in the following SMD:</p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="st0">&quot;transport&quot;</span>:<span class="st0">&quot;POST&quot;</span>,</div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="st0">&quot;envelope&quot;</span>:<span class="st0">&quot;JSON-RPC-2.0&quot;</span>,</div>
</li>
<li class="li2">
<div class="de2">&nbsp; <span class="st0">&quot;contentType&quot;</span>:<span class="st0">&quot;application<span class="es0">\/</span>json&quot;</span>,</div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="st0">&quot;SMDVersion&quot;</span>:<span class="st0">&quot;2.0&quot;</span>,</div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="st0">&quot;target&quot;</span>:<span class="st0">&quot;<span class="es0">\/</span>api<span class="es0">\/</span>v1<span class="es0">\/</span>jsonrpc.php&quot;</span>,</div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="st0">&quot;services&quot;</span>: <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; <span class="st0">&quot;add&quot;</span>:<span class="br0">&#123;</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="st0">&quot;envelope&quot;</span>:<span class="st0">&quot;JSON-RPC-2.0&quot;</span>,</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="st0">&quot;transport&quot;</span>:<span class="st0">&quot;POST&quot;</span>,</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="st0">&quot;parameters&quot;</span>:<span class="br0">&#91;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span><span class="st0">&quot;type&quot;</span>:<span class="st0">&quot;integer&quot;</span>,<span class="st0">&quot;name&quot;</span>:<span class="st0">&quot;x&quot;</span>,<span class="st0">&quot;optional&quot;</span>:<span class="kw2">false</span><span class="br0">&#125;</span>,</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span><span class="st0">&quot;type&quot;</span>:<span class="st0">&quot;integer&quot;</span>,<span class="st0">&quot;name&quot;</span>:<span class="st0">&quot;y&quot;</span>,<span class="st0">&quot;optional&quot;</span>:<span class="kw2">false</span><span class="br0">&#125;</span><span class="br0">&#93;</span>,</div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="st0">&quot;returns&quot;</span>:<span class="st0">&quot;array&quot;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp;<span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#125;</span>,</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;<span class="st0">&quot;methods&quot;</span>:<span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp;<span class="st0">&quot;add&quot;</span>:<span class="br0">&#123;</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span class="st0">&quot;envelope&quot;</span>:<span class="st0">&quot;JSON-RPC-2.0&quot;</span>,</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span class="st0">&quot;transport&quot;</span>:<span class="st0">&quot;POST&quot;</span>,</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span class="st0">&quot;parameters&quot;</span>:<span class="br0">&#91;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span class="br0">&#123;</span><span class="st0">&quot;type&quot;</span>:<span class="st0">&quot;integer&quot;</span>,<span class="st0">&quot;name&quot;</span>:<span class="st0">&quot;x&quot;</span>,<span class="st0">&quot;optional&quot;</span>:<span class="kw2">false</span><span class="br0">&#125;</span>,</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span class="br0">&#123;</span><span class="st0">&quot;type&quot;</span>:<span class="st0">&quot;integer&quot;</span>,<span class="st0">&quot;name&quot;</span>:<span class="st0">&quot;y&quot;</span>,<span class="st0">&quot;optional&quot;</span>:<span class="kw2">false</span><span class="br0">&#125;</span><span class="br0">&#93;</span>,</div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span class="st0">&quot;returns&quot;</span>:<span class="st0">&quot;array&quot;</span><span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp;<span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
</ol>
</div>
<p>jQuery does not support calling JSON-RPC services out of the box, but fourtenly there is plenty of plugins for jquery that fixes this. One is the JSON-RPC client found <a href="http://www.tanabi.com/projects/jsonrpc ">here</a>. Download the client and put the javascript files into your <code>/js</code> folder. Then create a new file <code>test.html</code> and add the following html:</p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&lt;html&gt;
</div>
</li>
<li class="li1">
<div class="de1">&lt;head&gt;
</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &lt;script LANGUAGE=&quot;javascript&quot; SRC=&quot;js/jquery-1.3.min.js&quot;&gt;&lt;/script&gt;
</div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; &lt;script LANGUAGE=&quot;javascript&quot; SRC=&quot;js/json2.js&quot;&gt;&lt;/script&gt;
</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &lt;script LANGUAGE=&quot;javascript&quot; SRC=&quot;js/jquery.zend.jsonrpc.js&quot;&gt;&lt;/script&gt;
</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &lt;script&gt;
</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $(document).ready(function(){
</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; test = jQuery.Zend.jsonrpc({url: &#8216;/api/v1/jsonrpc.php&#8217;});
</div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; alert(test.add(1,1)['result']);
</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; });
</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &lt;/script&gt;
</div>
</li>
<li class="li1">
<div class="de1">&lt;/head&gt;
</div>
</li>
<li class="li1">
<div class="de1">&lt;body&gt;
</div>
</li>
<li class="li2">
<div class="de2">&lt;/body&gt;
</div>
</li>
<li class="li1">
<div class="de1">&lt;/html&gt;
</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
</ol>
</div>
<p>We are all done! Browsing test.html should result in an alert box containg the result.<br />
<a href="http://sourcecodebean.com/wp-content/uploads/2010/01/result.png"><img src="http://sourcecodebean.com/wp-content/uploads/2010/01/result.png" alt="result" title="result" width="420" height="153" class="aligncenter size-full wp-image-442" /></a></p>
<p>Congratulations! You have created a JSON-RPC service!</p>
<p> <br/><br />
Read more about the Zend Framework:</p>
<ul>
<li><a href="http://sourcecodebean.com/archives/creating-a-custom-view-helper-in-the-zend-framework/6">Creating a custom View Helper in the Zend Framework</a></li>
<li><a href="http://sourcecodebean.com/archives/friendly-urls-and-the-zend-router/31">Friendly URLs and the Zend</a></li>
<li><a href="http://sourcecodebean.com/archives/upgrading-from-zend-framework-1-7-to-1-9-the-autoloader/414">Upgrading from Zend Framework 1.7 to 1.9 – The autoloader</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://sourcecodebean.com/archives/creating-a-json-rpc-service-using-zend-json-server/422/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Upgrading from Zend Framework 1.7 to 1.9 &#8211; The autoloader</title>
		<link>http://sourcecodebean.com/archives/upgrading-from-zend-framework-1-7-to-1-9-the-autoloader/414</link>
		<comments>http://sourcecodebean.com/archives/upgrading-from-zend-framework-1-7-to-1-9-the-autoloader/414#comments</comments>
		<pubDate>Wed, 30 Dec 2009 16:54:56 +0000</pubDate>
		<dc:creator>Peter</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Web]]></category>
		<category><![CDATA[Zend Framework]]></category>

		<guid isPermaLink="false">http://sourcecodebean.com/?p=414</guid>
		<description><![CDATA[Today I upgraded a project we started working on last year from Zend Framework 1.7 to Zend Framework 1.9. I excepted to run into several API incompatibilities, but the only problem I got was the autoloader.
In Zend 1.7, and earlier versions, the autoloader was registered like this:



&#160;


require_once &#34;Zend/Loader.php&#34;;


Zend_Loader::registerAutoload&#40;&#41;;


&#160;



In Zend Framwork 1.9 this has changed slightly, [...]]]></description>
			<content:encoded><![CDATA[<p>Today I upgraded a project we started working on last year from Zend Framework 1.7 to Zend Framework 1.9. I excepted to run into several API incompatibilities, but the only problem I got was the autoloader.</p>
<p>In Zend 1.7, and earlier versions, the autoloader was registered like this:</p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="kw1">require_once</span> <span class="st0">&quot;Zend/Loader.php&quot;</span>;</div>
</li>
<li class="li1">
<div class="de1">Zend_Loader::<span class="me2">registerAutoload</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
</ol>
</div>
<p>In Zend Framwork 1.9 this has changed slightly, you now have to register the namespaces you want to autoload:</p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="kw1">require_once</span> <span class="st0">&#8216;Zend/Loader/Autoloader.php&#8217;</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="re0">$loader</span> = Zend_Loader_Autoloader::<span class="me2">getInstance</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="re0">$loader</span>-&gt;<span class="me1">registerNamespace</span><span class="br0">&#40;</span><span class="st0">&#8216;Dqc_&#8217;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li2">
<div class="de2">&nbsp;</div>
</li>
</ol>
</div>
<p>This was the only change we needed to do to upgrade from 1.7 to 1.9, quite impressive! </p>
]]></content:encoded>
			<wfw:commentRss>http://sourcecodebean.com/archives/upgrading-from-zend-framework-1-7-to-1-9-the-autoloader/414/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Getting started with the Zend Framework</title>
		<link>http://sourcecodebean.com/archives/getting-started-with-the-zend-framework/374</link>
		<comments>http://sourcecodebean.com/archives/getting-started-with-the-zend-framework/374#comments</comments>
		<pubDate>Sun, 13 Dec 2009 21:53:00 +0000</pubDate>
		<dc:creator>Peter</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Web]]></category>
		<category><![CDATA[Zend Framework]]></category>

		<guid isPermaLink="false">http://sourcecodebean.com/?p=374</guid>
		<description><![CDATA[It used to be a bit tricky to get started with the Zend Framework. The Zend Framework is very flexible and allows you to set it up in almost any way that fits your needs. This means for example that the directory structure and location of files is up to you, however &#8211; there is [...]]]></description>
			<content:encoded><![CDATA[<p>It used to be a bit tricky to get started with the Zend Framework. The Zend Framework is very flexible and allows you to set it up in almost any way that fits your needs. This means for example that the directory structure and location of files is up to you, however &#8211; there is a recommended layout. When I first started using Zend I had to figure out this by looking at examples and reading the (at that time) rather poor documentation available. In Zend Framework 1.9 a tool, <code>zf.sh</code>, was introduced. It simplifies creating a new site a lot. In this blogpost I will guide you though the process of setting up a Zend development environment in OS X. The only part that is OS X specific is MAMP. Zend Framework runs just fine under Windows and Linux as well.  </p>
<p><strong>Step 1 &#8211; Getting a *AMP setup (LAMP, MAMP, WAMP)</strong><br />
The AMP (Apache, Mysql, PHP) stack is available for almost all modern operating systems. I am writing this on my Macbook, so in this tutorial I will use <a href="http://www.mamp.info">MAMP</a>. When I develop PHP in Windows I usually use WAMPServer and in Linux you can install the LAMP-stack using the packaging system in most distributions.  </p>
<p>Setting up MAMP is pretty straightforward, download the <a href="http://www.mamp.info/en/downloads/index.html">MAMP .dmg-file</a> and drag the MAMP folder to your Applications folder.<br />
<a href="http://sourcecodebean.com/wp-content/uploads/2009/12/mamp.png"><img src="http://sourcecodebean.com/wp-content/uploads/2009/12/mamp.png" alt="mamp" title="mamp" width="423" height="344" class="aligncenter size-full wp-image-384" /></a></p>
<p>Start the application and press the &#8220;Open start page&#8221; button to make sure everything works. On the start page you will find information about your site, phpInfo, phpMyAdmin and SqLiteManager. We will get back to configuring the http root directory later.</p>
<p><strong>Step 2 &#8211; Download and install Zend Framework</strong><br />
Go to the <a href="http://framework.zend.com/download/current/">framwork download page</a> and download the minimal distribution. In this tutorial I am using 1.9.6, but the instructions will probably apply to all 1.9 versions. </p>
<p>Extract the downloaded file and move the folder to a shared location, for example /usr/local/. Next step is to create an alias for the zf.sh tool. Edit your ~/.bash_profile and add the following line (change the path to where you moved the extracted files):</p>
<blockquote><p><code>zf=/usr/local/ZendFramework1.9/bin/zf.sh</code></p></blockquote>
<p>This will allow you execute the zf tool without using the full path. Try it out by executing <code>zf show version</code>, it should return the version number of the file you downloaded.</p>
<blockquote><p><code><br />
$ zf show version<br />
Zend Framework Version: 1.9.6<br />
</code></p></blockquote>
<p><strong>Step 3 &#8211; Create your project</strong><br />
Go to the folder where you want to create your new project, in my case ~/Development/. Run <code>zf create project zf-tutorial</code>. This will setup the default directory structure and create the necessary files. </p>
<p><a href="http://sourcecodebean.com/wp-content/uploads/2009/12/zendstructure.png"><img src="http://sourcecodebean.com/wp-content/uploads/2009/12/zendstructure.png" alt="Zend Framework directory structure" title="Zend Framework directory structure" width="252" height="397" class="aligncenter size-full wp-image-386" /></a></p>
<p>The application/ folder is where the source code for your website lives. It contains separate folder for models, views and controllers. The public/ folder is the folder that is going to be your document root. </p>
<p>Now you need to copy the Zend library (in my case /usr/local/ZendFramework1.9/library/Zend) or create a symlink for it so your site can find the Zend files. I prefer using a symlink: </p>
<blockquote><p><code><br />
$ cd ~/Development/zf-tutorial/library<br />
$ ln -s /usr/local/ZendFramework1.9/library/Zend/ Zend<br />
</code></p></blockquote>
<p><strong>Step 4 &#8211; Run the project</strong><br />
The last step before we will have running site up is to configure the step that we skipped in Step 1, configuring the Apache document root.<br />
<a href="http://sourcecodebean.com/wp-content/uploads/2009/12/sitesettings.png"><img src="http://sourcecodebean.com/wp-content/uploads/2009/12/sitesettings.png" alt="sitesettings" title="sitesettings" width="359" height="238" class="aligncenter size-full wp-image-388" /></a></p>
<p>Open up MAMP and click the preferences button, under the apache tab you will find the document root. Click select and navigate to the &#8220;public&#8221; folder in your zend project. Apply the settings and restart the server. </p>
<p>Now open your browser and direct it to <a href="http://localhost">http://localhost</a> and you should see the default welcomescreen:<br />
<a href="http://sourcecodebean.com/wp-content/uploads/2009/12/zenddefault.png"><img src="http://sourcecodebean.com/wp-content/uploads/2009/12/zenddefault.png" alt="zenddefault" title="zenddefault" width="610" height="408" class="aligncenter size-full wp-image-390" /></a></p>
<p>Now open your <code>application/controllers/IndexController.php</code> and start hacking your code!</p>
<p> <br/><br />
If you want to learn more about the Zend Framework i have some posts on some more advanced topics:</p>
<ul>
<li><a href="http://sourcecodebean.com/archives/creating-a-custom-view-helper-in-the-zend-framework/6">Creating a custom View Helper in the Zend Framework</a></li>
<li><a href="http://sourcecodebean.com/archives/friendly-urls-and-the-zend-router/31">Friendly URLs and the Zend</a></li>
<li><a href="http://sourcecodebean.com/archives/upgrading-from-zend-framework-1-7-to-1-9-the-autoloader/414">Upgrading from Zend Framework 1.7 to 1.9 – The autoloader</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://sourcecodebean.com/archives/getting-started-with-the-zend-framework/374/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Book review: ASP.NET MVC 1.0 &#8211; Test Driven Development</title>
		<link>http://sourcecodebean.com/archives/book-review-asp-net-mvc-1-0-test-driven-development/354</link>
		<comments>http://sourcecodebean.com/archives/book-review-asp-net-mvc-1-0-test-driven-development/354#comments</comments>
		<pubDate>Wed, 09 Dec 2009 09:28:25 +0000</pubDate>
		<dc:creator>Peter</dc:creator>
				<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Microsoft]]></category>
		<category><![CDATA[Web]]></category>

		<guid isPermaLink="false">http://sourcecodebean.com/?p=354</guid>
		<description><![CDATA[About a month ago I finished reading the book ASP.NET MVC 1.0 &#8211; Test Driven Development by Emad Ibrahim. The book weighs in only at about 300 pages, making it easily something you can read in a couple of nights. The book is written in tutorial fashion and is is probably best read with a [...]]]></description>
			<content:encoded><![CDATA[<p>About a month ago I finished reading the book ASP.NET MVC 1.0 &#8211; Test Driven Development by Emad Ibrahim. The book weighs in only at about 300 pages, making it easily something you can read in a couple of nights. The book is written in tutorial fashion and is is probably best read with a laptop running Visual Studio on your lap, so you can follow the examples in the book. The paradigm of the book is Problem, Design, Solution. Emand gudies the reader though the full process of creating a web application in a Test Driven manner. </p>
<p>Besides from only presenting MVC and TTD Emand presents several very useful libraries for Test Driven Development:</p>
<ul>
<li>Moq &#8211; A mocking library for .NET that uses the power of LINQ to create mocks.</li>
<li>Ninject &#8211; Dependency injection library for .NET</li>
<li>MBunit &#8211; An alternative to VSTest</li>
</ul>
<p>I think the book gives a good kickstart in ASP.NET MVC and TTD. My favorite part of the book was actually not reading about MVC itself, it was reading about testing it &#8211; Emad shows the strengths of MVC by showing how it makes testing easier. </p>
]]></content:encoded>
			<wfw:commentRss>http://sourcecodebean.com/archives/book-review-asp-net-mvc-1-0-test-driven-development/354/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>ZFS for home NAS?</title>
		<link>http://sourcecodebean.com/archives/zfs-for-home-nas/323</link>
		<comments>http://sourcecodebean.com/archives/zfs-for-home-nas/323#comments</comments>
		<pubDate>Mon, 07 Dec 2009 19:58:36 +0000</pubDate>
		<dc:creator>Peter</dc:creator>
				<category><![CDATA[Storage]]></category>
		<category><![CDATA[UNIX]]></category>

		<guid isPermaLink="false">http://sourcecodebean.com/?p=323</guid>
		<description><![CDATA[I have been doing some research on NASes for home use. I basically want a NAS that offers redundancy (some form of raid), the ability to add disks as I go. It should also support at least SMB as file sharing protocol (but preferable others as well), and of course not be too expensive. All [...]]]></description>
			<content:encoded><![CDATA[<p>I have been doing some research on NASes for home use. I basically want a NAS that offers redundancy (some form of raid), the ability to add disks as I go. It should also support at least SMB as file sharing protocol (but preferable others as well), and of course not be too expensive. All home NASes I have found yet has been lacking on at least one of the above criteria.</p>
<p>I have read about people using ZFS on FreeBSD or OpenSolaris for their storage servers. ZFS is a open source file system developed by Sun Microsystems which has some features that makes it very compelling for a file storage server. Unfourtanly ZFS is not available on Linux at the time of writing (i think it is some licensing issues that is preventing a port of it), if it were I would definitely go for it. </p>
<p>To give it a try, i downloaded OpenSolaris 2009.6 and installed it as a virtual machine in VMware Fusion. Instead of having to add several virtual disks to the VM, i decided to test the features of ZFS using regular files (ZFS can use files as disk devices). An easy way to create some &#8220;disks&#8221; is to use the <code>mkfile</code> command, it will create a file that can be used a disk device:</p>
<blockquote><p><code># mkfile 100m /tmp/disk1<br />
# mkfile 100m /tmp/disk2<br />
# mkfile 100m /tmp/disk3<br />
# mkfile 100m /tmp/disk4</code></p></blockquote>
<p>ZFS has tree leveles. The highest level is a ZFS pool, which can consist of several ZFS filesystems. A ZFS filesystem consists of one or more devices. Filesystems within a pool share its resources and are not restricted to a fixed size. You can add or remove devices to a pool (for example to increase your storage space), while the pool is running. Devices in a filesystem can be configured in mirrored mode or in RAIDZ mode to offer redundancy. ZFS also supports filesystem level snapshots and cloning from existing file systems.  The two main ZFS commands are:</p>
<blockquote><p><code><strong>zpool</strong> - Manages the pools and the devices within them<br />
<strong>zfs</strong> - Manages ZFS filesystems</code> </p></blockquote>
<p>Ok, so lets create a pool from the disks we created earlier:</p>
<blockquote><p><code># zpool create storage /tmp/disk1 /tmp/disk2</code></p></blockquote>
<blockquote><p><code># zpool list<br />
NAME      SIZE   USED  AVAIL    CAP  HEALTH  ALTROOT<br />
rpool    7.94G  4.28G  3.66G    53%  ONLINE  -<br />
storage   191M  74.5K   191M     0%  ONLINE  -</code></p></blockquote>
<p>As you can see we combined two disks into one pool. The filesystem automatically gets mounted on /storage (this is the default mount point, it can be changed). No volume management, configuration or formatting is needed. Lets destoy this pool to create a more interesting one. </p>
<blockquote><p>
<code># zpool destroy storage</code></p></blockquote>
<blockquote><p><code># zpool list<br />
NAME    SIZE   USED  AVAIL    CAP  HEALTH  ALTROOT<br />
rpool  7.94G  4.36G  3.58G    54%  ONLINE  -</code></p></blockquote>
<p>As you can see, it is gone. Lets create a new pool using RAIDZ (a form of raid, similar to RAID5):</p>
<blockquote><p><code># zpool create storage raidz /tmp/disk1 /tmp/disk2 /tmp/disk3</code></p></blockquote>
<blockquote><p><code># zpool list<br />
NAME      SIZE   USED  AVAIL    CAP  HEALTH  ALTROOT<br />
rpool    7.94G  4.38G  3.56G    55%  ONLINE  -<br />
storage   286M   140K   286M     0%  ONLINE  -<br />
</code></p></blockquote>
<p>One thing that’s a little different in a ZFS raidz pool versus other RAID-5 filesystems is that the reported available disk space doesn’t subtract the space required by parity. Of course parity will take up space, so this is something to keep in mind when monitoring the disks. We can monitor the status of the pool by using the <code>zpool status</code> command:</p>
<blockquote><p><code># zpool status storage<br />
  pool: storage<br />
 state: ONLINE<br />
 scrub: none requested<br />
config:</p>
<p>        NAME            STATE     READ WRITE CKSUM<br />
        storage         ONLINE       0     0     0<br />
          raidz1        ONLINE       0     0     0<br />
            /tmp/disk1  ONLINE       0     0     0<br />
            /tmp/disk2  ONLINE       0     0     0<br />
            /tmp/disk3  ONLINE       0     0     0</p>
<p>errors: No known data errors</code></p></blockquote>
<p>After some playing around with ZFS i certainly think it would be a great choice for a storage server. It is way easier to use than the software/LVM solutions i have tried on Linux. The biggest drawback would be OpenSolaris itself, I just find the GNU application userland easier to use compared to the Solaris one. Maybe I should give Nexenta (OpenSolaris Kernel, GNU application userland) a chance?</p>
<p>Read more:<br />
<a href="http://en.wikipedia.org/wiki/ZFS">ZFS on Wikipedia</a><br />
<a href="http://blogs.sun.com/bonwick/entry/raid_z">RAID-Z</a></p>
]]></content:encoded>
			<wfw:commentRss>http://sourcecodebean.com/archives/zfs-for-home-nas/323/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Moving a database from MSSQL 2008 to MSSQL 2005</title>
		<link>http://sourcecodebean.com/archives/moving-a-database-from-mssql-2008-to-mssql-2005/313</link>
		<comments>http://sourcecodebean.com/archives/moving-a-database-from-mssql-2008-to-mssql-2005/313#comments</comments>
		<pubDate>Sat, 28 Nov 2009 12:19:00 +0000</pubDate>
		<dc:creator>Peter</dc:creator>
				<category><![CDATA[Microsoft]]></category>
		<category><![CDATA[SQL Server]]></category>

		<guid isPermaLink="false">http://sourcecodebean.com/?p=313</guid>
		<description><![CDATA[So I restored a backup from from MSSQL 2005 to a MSSQL 2008 database, which kept the database in &#8220;SQL 2005 compatibly mode&#8221;. I thought that this would mean that the database could actually be backed up from the MSSQL 2008 server to the MSSQL 2005 server, however it turns out that this is not [...]]]></description>
			<content:encoded><![CDATA[<p>So I restored a backup from from MSSQL 2005 to a MSSQL 2008 database, which kept the database in &#8220;SQL 2005 compatibly mode&#8221;. I thought that this would mean that the database could actually be backed up from the MSSQL 2008 server to the MSSQL 2005 server, however it turns out that this is not the case. Backing it up from 2008 and trying to restore it, resulted in the the following slightly cryptic error:</p>
<blockquote><p>
An exception occurred while executing a Transact-SQL statement or batch. (Microsoft.SqlServer.Express.ConnectionInfo)<br />
The media family on device &#8216;C:\Temp\db.bak&#8217; is incorrectly formed. SQL Server cannot process this media family.<br />
RESTORE HEADERONLY is terminating abnormally. (Microsoft SQL Server, Error: 3241)
</p></blockquote>
<p>After some googeling it turns out that MSSQL 2005 can not read backups from 2008. The solution I found to the problem was to export the database as a SQL script, and running the script on the SQL 2005 server. Maybe not the best solution, but it saved my day. </p>
<p><strong>This is how you create the script file:</strong><br />
In Object Explorer in SQL 2008 management studio, right-click the database, select Tasks->Generate Scripts. In the options dialog enable everything, including Script Data. Make sure you select &#8220;Script for SQL 2005&#8243; (otherwise you will export a SQL 2008 script file). Then run the script on your SQL 2005 server and hopefully you are done!</p>
]]></content:encoded>
			<wfw:commentRss>http://sourcecodebean.com/archives/moving-a-database-from-mssql-2008-to-mssql-2005/313/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Rename a Folder using EPiServer.Web.Hosting.UnifiedDirectory</title>
		<link>http://sourcecodebean.com/archives/rename-a-folder-using-episerver-web-hosting-unifieddirectory/304</link>
		<comments>http://sourcecodebean.com/archives/rename-a-folder-using-episerver-web-hosting-unifieddirectory/304#comments</comments>
		<pubDate>Mon, 05 Oct 2009 00:02:47 +0000</pubDate>
		<dc:creator>Peter</dc:creator>
				<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[EPiServer]]></category>

		<guid isPermaLink="false">http://sourcecodebean.com/?p=304</guid>
		<description><![CDATA[While reading the EPiServer 5 SDK documentation, i found this:
Rename a Folder
There is no Rename method on the EPiServer.Web.Hosting.UnifiedDirectory class. To rename a folder you need to call the MoveTo method as follows:



&#160;


protected void RenameFolder&#40;string path, string oldName, string name&#41;


&#123;


&#160; &#160; if &#40;IsFolder&#40;path&#41;&#41;


&#160; &#160; &#123;


&#160; &#160; &#160; &#160; UnifiedDirectory directory = 


&#160; &#160; &#160; &#160; [...]]]></description>
			<content:encoded><![CDATA[<p>While reading the EPiServer 5 SDK documentation, i found this:</p>
<blockquote><p><strong>Rename a Folder</strong></p>
<p>There is no Rename method on the EPiServer.Web.Hosting.UnifiedDirectory class. To rename a folder you need to call the MoveTo method as follows:</p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">protected <span class="kw4">void</span> RenameFolder<span class="br0">&#40;</span><span class="kw4">string</span> path, <span class="kw4">string</span> oldName, <span class="kw4">string</span> name<span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span>IsFolder<span class="br0">&#40;</span>path<span class="br0">&#41;</span><span class="br0">&#41;</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; UnifiedDirectory directory = </div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; System.<span class="me1">Web</span>.<span class="me1">Hosting</span>.<span class="me1">HostingEnvironment</span>.<span class="me1">VirtualPathProvider</span>.<span class="me1">GetDirectory</span><span class="br0">&#40;</span>path<span class="br0">&#41;</span> as UnifiedDirectory;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw4">int</span> e = <span class="nu0">-1</span>;</div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">while</span> <span class="br0">&#40;</span>path.<span class="me1">IndexOf</span><span class="br0">&#40;</span>oldName, ++e<span class="br0">&#41;</span> &gt; <span class="nu0">-1</span><span class="br0">&#41;</span> ;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; StringBuilder sb = new StringBuilder<span class="br0">&#40;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; sb.<span class="me1">Append</span><span class="br0">&#40;</span>path.<span class="me1">Substring</span><span class="br0">&#40;</span><span class="nu0">0</span>, e &#8211; <span class="nu0">1</span><span class="br0">&#41;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; sb.<span class="me1">Append</span><span class="br0">&#40;</span>name<span class="br0">&#41;</span>;</div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; sb.<span class="me1">Append</span><span class="br0">&#40;</span><span class="st0">&quot;/&quot;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; directory.<span class="me1">MoveTo</span><span class="br0">&#40;</span>sb.<span class="me1">ToString</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp;</div>
</li>
</ol>
</div>
</blockquote>
<p>What a convenient way of renaming a folder <img src='http://sourcecodebean.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  Good thing that you don&#8217;t have to do it too often.</p>
]]></content:encoded>
			<wfw:commentRss>http://sourcecodebean.com/archives/rename-a-folder-using-episerver-web-hosting-unifieddirectory/304/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
