<?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>Karl Katzke &#187; first application</title>
	<atom:link href="http://www.karlkatzke.com/categories/php/zend-framework/first-application/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.karlkatzke.com</link>
	<description>Geek of the Week</description>
	<lastBuildDate>Fri, 16 Dec 2011 19:54:18 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3</generator>
		<item>
		<title>Your First Zend Framework Application: Day Four</title>
		<link>http://www.karlkatzke.com/your-first-zend-framework-application-day-four/</link>
		<comments>http://www.karlkatzke.com/your-first-zend-framework-application-day-four/#comments</comments>
		<pubDate>Thu, 01 May 2008 14:07:06 +0000</pubDate>
		<dc:creator>karlkatzke</dc:creator>
				<category><![CDATA[first application]]></category>
		<category><![CDATA[howto]]></category>
		<category><![CDATA[webdev]]></category>
		<category><![CDATA[zend framework]]></category>
		<category><![CDATA[framework]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[zend]]></category>

		<guid isPermaLink="false">http://www.karlkatzke.com/?p=120</guid>
		<description><![CDATA[And now the fun begins! Today we&#8217;re going to really show some of the power of Zend Framework. All the steps that you&#8217;ve taken in the previous tutorials will suddenly make sense &#8212; you&#8217;re going to be set up to authenticate users in a few minutes flat. If you don&#8217;t know basic OOP (Object-Oriented Programming) [...]]]></description>
			<content:encoded><![CDATA[<p>And now the fun begins! Today we&#8217;re going to really show some of the power of Zend Framework. All the steps that you&#8217;ve taken in the previous tutorials will suddenly make sense &#8212; you&#8217;re going to be set up to authenticate users in a few minutes flat. </p>
<p>If you don&#8217;t know basic OOP (Object-Oriented Programming) principles, now would be a good time to go do some reading on them. We&#8217;re going to make heavy use of <a href="http://en.wikipedia.org/wiki/Inheritance_%28computer_science%29">inheritance</a>, as well as <a href="http://en.wikipedia.org/wiki/Method_overriding_%28programming%29">overriding</a>. Just keep in mind that PHP is not a strongly typed language. </p>
<p>Let&#8217;s get started. For authentication, we&#8217;re going to build the form the old fashioned way so that you can get a good example for &#8216;how it was done&#8217; versus &#8216;how smoothly it can be done&#8217; with Zend Framework. <span id="more-120"></span> Let&#8217;s create the login form. In /app/views/scripts/index/, create login.phtml &#8212; do note the .phtml extension on it. To keep us moving right along, here&#8217;s the code for it.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?</span> <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">empty</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">message</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">:</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
    <span style="color: #000000; font-weight: bold;">&lt;?=</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">message</span><span style="color: #000000; font-weight: bold;">?&gt;</span>
<span style="color: #000000; font-weight: bold;">&lt;?</span> <span style="color: #b1b100;">endif</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
&lt;form name=&quot;login&quot; action=&quot;index/login&quot; method=&quot;post&quot;&gt;
Login: &lt;input type=&quot;text&quot; name=&quot;login&quot; /&gt;&lt;br /&gt;
Password: &lt;input type=&quot;password&quot; name=&quot;password&quot; /&gt;&lt;br /&gt;
&lt;input type=&quot;submit&quot; name=&quot;submit&quot; value=&quot;submit&quot; /&gt;
&lt;/form&gt;</pre></div></div>

<div id="rightbox" style="width:340;float:right;font-size: 10px;margin-left: 10px; padding: 3px  ; border: 1px dotted black; background-color: #fefefe"><b>All Zend Framework Tutorials</b><br /><a href="http://www.karlkatzke.com/your-first-zend-framework-application-day-four/" title="View post Your First Zend Framework Application: Day Four">Your First Zend Framework Application: Day Four</a><br />
<a href="http://www.karlkatzke.com/your-first-zend-framework-application-day-thre/" title="View post Your First Zend Framework Application: Day Three">Your First Zend Framework Application: Day Three</a><br />
<a href="http://www.karlkatzke.com/your-first-zend-framework-application-day-two/" title="View post Your First Zend Framework Application: Day Two">Your First Zend Framework Application: Day Two</a><br />
<a href="http://www.karlkatzke.com/your-first-zend-framework-application-day-one/" title="View post Your First Zend Framework Application: Day One">Your First Zend Framework Application: Day One</a>
</div>
<p>Now we&#8217;ll head back to your controller. If you look at the work you did in the form, you&#8217;ll see that the index controller&#8217;s login action will be responsible for both displaying and processing this form. </p>
<p>First, to get the form to display, you&#8217;ll need to add just a blank login action to your IndexController. For security purposes, I&#8217;ve cleared out the &#8216;list of users&#8217; that was in yesterday&#8217;s indexAction() (we don&#8217;t really want to give an attacker a list of users to try, do we?) and replaced it with a <a href="http://framework.zend.com/manual/en/zend.controller.dispatcher.html">call to $this->_forward()</a> to direct users that come to the index page to the login. Later on, when we&#8217;re checking for authenticated users, we&#8217;ll replace this with a conditional.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">class</span> IndexController <span style="color: #000000; font-weight: bold;">extends</span> Zend_Controller_Action <span style="color: #009900;">&#123;</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: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">forward</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'login'</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;">function</span> loginAction<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
  <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Now, if you visit /index/login in your browser, you should get the login form. Let&#8217;s add some logic to make it do something. We&#8217;re going to use Zend_Auth&#8217;s database methods for this.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> loginAction<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #000088;">$params</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_getAllParams<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">empty</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$params</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'submit'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #000088;">$params</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'submit'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">'submit'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$auth</span> <span style="color: #339933;">=</span> Zend_Auth<span style="color: #339933;">::</span><span style="color: #004000;">getInstance</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #000088;">$adapt</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Zend_Auth_Adapter_DbTable<span style="color: #009900;">&#40;</span>Zend_Registry<span style="color: #339933;">::</span><span style="color: #004000;">get</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'db'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$adapt</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setTableName</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'users'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$adapt</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setIdentityColumn</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'id'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$adapt</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setCredentialColumn</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'password'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$adapt</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setCredential</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">sha1</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$param</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'password'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$adapt</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setIdentity</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">htmlspecialchars</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$param</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'login'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #000088;">$result</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$auth</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">authenticate</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$adapt</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">initView</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: #000088;">$result</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">isValid</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;">$storage</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Zend_Auth_Storage_Session<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                  <span style="color: #000088;">$storage</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">write</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$adapt</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getResultRowObject</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'id'</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;">$auth</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setStorage</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$storage</span><span style="color: #009900;">&#41;</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;">message</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'Login Successful!'</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</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;">message</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'Invalid login. Please try again.'</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></div></div>

<p>There&#8217;s a few very important things we want to note here. </p>
<ol>
<li>Zend_Auth is written in a <a href="http://en.wikipedia.org/wiki/Singleton_pattern">Singleton Pattern</a>.</li>
<li>We make use of the database handle that we stored in the registry in the front controller.</li>
<li>We&#8217;re encoding the password in the code before we send it to the database. In the database, the password is already encoded in sha1 format.</li>
<li>We&#8217;re setting the identity for later retrieval.</li>
<li>We pass a message back to the user via the view script.</li>
</ol>
<p>You know what? I know I promised that we&#8217;d get into some fancier stuff using Zend_Form and Zend_Mail, but I think that&#8217;s enough new concepts for one day. We&#8217;ll extend the tutorial into next week and spend tomorrow working with Zend_Form and Zend_Mail. </p>
<p>Happy coding!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.karlkatzke.com/your-first-zend-framework-application-day-four/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Your First Zend Framework Application: Day Three</title>
		<link>http://www.karlkatzke.com/your-first-zend-framework-application-day-thre/</link>
		<comments>http://www.karlkatzke.com/your-first-zend-framework-application-day-thre/#comments</comments>
		<pubDate>Wed, 30 Apr 2008 19:54:28 +0000</pubDate>
		<dc:creator>karlkatzke</dc:creator>
				<category><![CDATA[first application]]></category>
		<category><![CDATA[howto]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[webdev]]></category>
		<category><![CDATA[zend framework]]></category>
		<category><![CDATA[framework]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[zend]]></category>

		<guid isPermaLink="false">http://www.karlkatzke.com/?p=118</guid>
		<description><![CDATA[Today, let&#8217;s take a look at Zend_Db. Zend_Db implements a Table Data Gateway, in which the object is considered to be extended to have the properties of a table, as opposed to a Object Relational Model (ORM) / Data Access Object (DAO) where the object is considered to be a representation of the database object. [...]]]></description>
			<content:encoded><![CDATA[<p>Today, let&#8217;s take a look at Zend_Db. Zend_Db implements a Table Data Gateway, in which the object is considered to be extended to have the properties of a table, as opposed to a Object Relational Model (ORM) / Data Access Object (DAO) where the object is considered to be a representation of the database object. Philosophy aside, it&#8217;s a great tool, and we&#8217;re mostly interested in how to <i>use</i> it. It is worth noting that you can use <a href="http://www.karlkatzke.com/zend-framework-doctrine-2/">Zend Framework along with the excellent Doctrine ORM</a>&#8230; and the syntax is even pretty similar. </p>
<p>The general procedure when setting up Zend_Db is to create a bunch of objects that extend Zend_Db_Table_Abstract. When defining an object, you can define what table it connects to, what the primary key is, and any foreign keys that relate to it. Upon instantiating the object in your code, you can use it to build queries against it&#8217;s related table, which returns a collection of row sets for direct use in your applications. Today&#8217;s tutorial assumes that you&#8217;re very comfortable with looping and other control structures in PHP.<span id="more-118"></span></p>
<h2>Configuration File</h2>
<div id="rightbox" style="width:340;float:right;font-size: 10px;margin-left: 10px; padding: 3px  ; border: 1px dotted black; background-color: #fefefe"><b>All Zend Framework Tutorials</b><br /><a href="http://www.karlkatzke.com/your-first-zend-framework-application-day-four/" title="View post Your First Zend Framework Application: Day Four">Your First Zend Framework Application: Day Four</a><br />
<a href="http://www.karlkatzke.com/your-first-zend-framework-application-day-thre/" title="View post Your First Zend Framework Application: Day Three">Your First Zend Framework Application: Day Three</a><br />
<a href="http://www.karlkatzke.com/your-first-zend-framework-application-day-two/" title="View post Your First Zend Framework Application: Day Two">Your First Zend Framework Application: Day Two</a><br />
<a href="http://www.karlkatzke.com/your-first-zend-framework-application-day-one/" title="View post Your First Zend Framework Application: Day One">Your First Zend Framework Application: Day One</a>
</div>
<p>You should have a MySQL database accessible to your webserver. Knowing how to use MySQL is outside of the scope of this tutorial but the basic gist of what you need to do is &#8212; create a database, create a user and password for that database, and insert the SQL to create the tables. </p>
<p><a href='http://www.karlkatzke.com/wp-content/uploads/2008/04/zfapp.sql' target="_blank">ZFApp (Day 3) SQL</a></p>
<p>When you&#8217;ve collected that information, let&#8217;s write a configuration file. This file will go in app/config/db.ini.</p>

<div class="wp_syntax"><div class="code"><pre class="ini" style="font-family:monospace;"><span style="color: #000066; font-weight:bold;"><span style="">&#91;</span>dev<span style="">&#93;</span></span>
database.params.host<span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">localhost</span>
database.adapter<span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">pdo_mysql</span>
database.params.username<span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">foobaruser</span>
database.params.password<span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">foobar</span>
database.params.dbname<span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">zfapp</span></pre></div></div>

<p>Save that file, and then let&#8217;s go tell the front controller how to access the zfapp database. </p>
<h2>Front Controller</h2>
<p>The first thing we need to do is go back and visit our friend the Front Controller. It needs some setup if we&#8217;re to use Zend_Db. Let&#8217;s open up index.php and add a few lines. We&#8217;ll be using Zend_Config_Ini to load up the configuration file. Note the &#8216;dev&#8217; &#8211; that tells us to load up the area after the [dev] in the above .ini file. I use this to tell the difference between my dev and live configuration, since that keyword is set by a SetEnv statement in the Apache configuration file.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$dbconf</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Zend_Config_Ini<span style="color: #009900;">&#40;</span>BASEDIR<span style="color: #339933;">.</span><span style="color: #0000ff;">'/app/config/db.ini'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'dev'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Now that we&#8217;ve got a handle to the configuration file, we&#8217;ll use Zend_Db&#8217;s factory method to create a DB Connection.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$db</span> <span style="color: #339933;">=</span> Zend_Db<span style="color: #339933;">::</span><span style="color: #004000;">factory</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$dbconf</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">database</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>That&#8217;s it. That&#8217;s all we need to do. $db is now a database handle. Two lines of code! Zing! The only other things that we&#8217;ll find helpful here is setting this DB handle as the default handle for tables. I also register the DB handle with the registry so that I have an easy way to get it back later if I want to do something deep and complicated with the db.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">Zend_Db_Table_Abstract<span style="color: #339933;">::</span><span style="color: #004000;">setDefaultAdapter</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$db</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
Zend_Registry<span style="color: #339933;">::</span><span style="color: #004000;">set</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'db'</span><span style="color: #339933;">,</span><span style="color: #000088;">$db</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<h2>Using the DB</h2>
<p>Tomorrow, we&#8217;ll really get into using the database for something, but for today let&#8217;s just finish the prep work and make a basic use of our new toy. </p>
<p>First, we need a model to access. Make sure you&#8217;ve got the models on your include path in your front controller:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #990000;">set_include_path</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">ini_get</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'include_path'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span>PATH_SEPARATOR<span style="color: #339933;">.</span>BASEDIR<span style="color: #339933;">.</span><span style="color: #0000ff;">'app/models'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Now, we&#8217;ll create our first model. A model is a basic file that just tells the database driver where a table is, and provides some defaults. In /app/models/users.php, we&#8217;ll want to extend a Zend_Db_Table_Abstract as follows:</p>
<pre>
class Users extends Zend_Db_Table_Abstract {
   protected $_name = 'users';
   protected $_primary = 'id
}
</pre>
<p>&#8230; and that&#8217;s it. Since you included the models directory in your include path, all you need to do is instantiate a Users module anywhere in your application, and you can access the users table via the db handle you created in your front controller and assigned as default. Pretty neat, huh?</p>
<p>Ok, let&#8217;s select some rows out. </p>
<p>Head over to the /app/controllers/IndexController.php that you made yesterday. In the indexAction() function, place this code:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><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: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">initView</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Initialize the view object for this module</span>
  <span style="color: #000088;">$user</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Users<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Users Table Object. </span>
  <span style="color: #000088;">$rowset</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$user</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">select</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Created a default 'select all' query</span>
  <span style="color: #000088;">$list_of_users</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$rowset</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$row</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$list_of_users</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$row</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">id</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</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;">userlist</span> <span style="color: #339933;">=</span> <span style="color: #990000;">join</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$list_of_users</span><span style="color: #339933;">,</span><span style="color: #0000ff;">', '</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Concatenate the list of users and make it available to the view. </span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>And we&#8217;ll head over to the view script you created yesterday &#8230; /app/views/scripts/index/index.phtml &#8230; and add in a line to echo that userlist. Don&#8217;t forget to add the carat-questionmarks here, of course.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">userlist</span><span style="color: #339933;">;</span></pre></div></div>

<p>&#8230; and as Emeril says, Bang! You&#8217;re reading from your database. </p>
<p>Tomorrow we&#8217;ll do some &#8216;heavy&#8217; lifting &#8212; we&#8217;ll set up Zend_Auth to authenticate users from the database, a Zend_Form to allow users to sign up, and a Zend_Mail to send users their passwords when they&#8217;ve forgotten it. </p>
]]></content:encoded>
			<wfw:commentRss>http://www.karlkatzke.com/your-first-zend-framework-application-day-thre/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
		<item>
		<title>Your First Zend Framework Application: Day Two</title>
		<link>http://www.karlkatzke.com/your-first-zend-framework-application-day-two/</link>
		<comments>http://www.karlkatzke.com/your-first-zend-framework-application-day-two/#comments</comments>
		<pubDate>Tue, 29 Apr 2008 06:23:04 +0000</pubDate>
		<dc:creator>karlkatzke</dc:creator>
				<category><![CDATA[first application]]></category>
		<category><![CDATA[howto]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[webdev]]></category>
		<category><![CDATA[zend framework]]></category>
		<category><![CDATA[framework]]></category>
		<category><![CDATA[zend]]></category>

		<guid isPermaLink="false">http://www.karlkatzke.com/?p=117</guid>
		<description><![CDATA[Yesterday we left off with a basic folder structure in a Subversion repository, including the Zend Framework libs. It isn&#8217;t really much to look at, and it just doesn&#8217;t do anything. Not impressive. Let&#8217;s fix that. Today we&#8217;ll be covering the front controller and some basic modules and actions. You still won&#8217;t need a database [...]]]></description>
			<content:encoded><![CDATA[<p><a href="/your-first-zend-framework-application-day-on/">Yesterday</a> we left off with a basic folder structure in a Subversion repository, including the Zend Framework libs. It isn&#8217;t really much to look at, and it just doesn&#8217;t <i>do</i> anything. Not impressive. Let&#8217;s fix that. </p>
<p>Today we&#8217;ll be covering the front controller and some basic modules and actions. You still won&#8217;t need a database at this point, but you will need to have Apache configured correctly. You&#8217;ll also want to have the <a href="http://framework.zend.com/manual/en/">Zend Framework Reference Guide</a> within easy reach. </p>
<p>Before we get started, make sure that your Apache configuration <span id="more-117"></span>(we&#8217;re assuming you&#8217;re doing this on a stanadlone server, your local machine using MAMP or WAMP, or a virtual host, and not on shared hosting)  is set up so that your document root is your /html folder, and AllowOverrides is set to All for the directory. If you don&#8217;t know how to do this, refer to your Web Server&#8217;s documentation or ask someone.</p>
<div id="rightbox" style="width:340;float:right;font-size: 10px;margin-left: 10px; padding: 3px  ; border: 1px dotted black; background-color: #fefefe"><b>All Zend Framework Tutorials</b><br /><a href="http://www.karlkatzke.com/your-first-zend-framework-application-day-four/" title="View post Your First Zend Framework Application: Day Four">Your First Zend Framework Application: Day Four</a><br />
<a href="http://www.karlkatzke.com/your-first-zend-framework-application-day-thre/" title="View post Your First Zend Framework Application: Day Three">Your First Zend Framework Application: Day Three</a><br />
<a href="http://www.karlkatzke.com/your-first-zend-framework-application-day-two/" title="View post Your First Zend Framework Application: Day Two">Your First Zend Framework Application: Day Two</a><br />
<a href="http://www.karlkatzke.com/your-first-zend-framework-application-day-one/" title="View post Your First Zend Framework Application: Day One">Your First Zend Framework Application: Day One</a>
</div>
<p>The first thing we&#8217;re going to do is set up your front controller. Every time someone accesses your application, they access the front controller, and the front controller is responsible for loading up everything else that the user needs to see or the application needs to process. The front controller is one  of the few PHP files that lives in your /html directory. Let&#8217;s create it, and call it index.php. </p>
<p>The first few things that your front controller needs to know are where the front controller itself is, what the path to the Zend libraries are, and where your controllers are so that it can dispatch the request to them. </p>
<p>Let&#8217;s tackle the location first. I generally don&#8217;t depend on the file to know where its by using the</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #990000;">dirname</span><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></pre></div></div>

<p> trick &#8212; I tend more towards setting the specific directory structure based on a location variable set in my apache configuration using <code>SetEnv</code>. So the first few lines of my front controller looks like:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'ENV'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">'dev'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #990000;">define</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'BASE'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'/Users/kkatzke/work/firstapp'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
alit<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #990000;">define</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'BASE'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'/var/www/sites/firstapp.katzke.net'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>From there, you use the base directory constant to add the appropriate paths to your PHP include path. In your case, you&#8217;re working in your home directory, so your path would look like &#8216;/home/myusername/myprojectname/lib/Zend&#8217;. BASE would equal &#8216;/home/myusername/myprojectname/&#8217;, so you would add to your index.php:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #990000;">set_include_path</span><span style="color: #009900;">&#40;</span>BASE<span style="color: #339933;">.</span><span style="color: #0000ff;">'lib/'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Now it&#8217;s time to use your first big of Zend Framework magic. Zend Framework uses the <a href="http://us.php.net/spl_autoload">Standard PHP Library (SPL) Autoload</a> functionality. All of the Framework libraries are named the same as their path from the base &#8212; so the object Zend_Form_Element_Text is in Zend/Form/Element/Text.php. Let&#8217;s go ahead and enable Zend Loader, and then I&#8217;ll explain what it does.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">require_once</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Zend/Loader.php'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
Zend_Loader<span style="color: #339933;">::</span><span style="color: #004000;">registerAutoload</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Now that Zend Loader has registered an autoload handler, any time you want to use an object within the Zend Framework, you don&#8217;t have to be sure you&#8217;ve called &#8216;require_once()&#8217; yet &#8212; it&#8217;ll &#8220;autoload&#8221; itself in based on the name. Let&#8217;s go ahead and use that to set up the MVC Layout&#8230; but we&#8217;ll leave it commented out for now. You&#8217;ll find out why later.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#Zend_Layout::startMvc();</span></pre></div></div>

<p>Note, again, that we didn&#8217;t have to include any extra files to access the Zend_Layout option! Pretty cool, huh? Let&#8217;s hurry up and get a site working. The last part of the Front Controller is the Dispatch processor. Dispatching is like saying &#8216;ok, our environment is set up, let&#8217;s go&#8217; within Zend &#8212; it takes the request, does some magic, and spits out a response. It should be the last thing that happens in your front controller.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">Zend_Controller_Front<span style="color: #339933;">::</span><span style="color: #004000;">run</span><span style="color: #009900;">&#40;</span>BASE<span style="color: #339933;">.</span><span style="color: #0000ff;">'app/controllers'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>There&#8217;s a lot more that could be said about the front controller and dispatch loop/process, but you can go <a href="http://framework.zend.com/manual/en/zend.controller.front.html">peruse it in the manual</a> &#8212; we&#8217;re focused mainly on getting a new app up as fast as we can.</p>
<p>Now, note when we called that front controller, we addressed the BASE.&#8217;app/controllers&#8217; directory &#8212; this is where we&#8217;re going to work next. First, make sure your Front Controller (index.php) file looks something like this, and then let&#8217;s move on.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'ENV'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">'dev'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #990000;">define</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'BASE'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'/users/home/myusername/myprojectname/'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
alit<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #990000;">define</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'BASE'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'/home/myusername/myprojectname/);
}
&nbsp;
set_include_path(BASE.'</span>lib<span style="color: #339933;">/</span><span style="color: #0000ff;">');
&nbsp;
require_once('</span>Zend<span style="color: #339933;">/</span>Loader<span style="color: #339933;">.</span>php<span style="color: #0000ff;">');
Zend_Loader::registerAutoload();
&nbsp;
#Zend_Layout::startMvc();
&nbsp;
Zend_Controller_Front::run(BASE.'</span>app<span style="color: #339933;">/</span>controllers<span style="color: #0000ff;">');</span></pre></div></div>

<h2>Modules</h2>
<p>You need two basic modules and a few templates to have your first basic, working application. Let&#8217;s add an index module and a template. </p>
<p>In BASE./app/controllers, let&#8217;s create a file named IndexController.php. Capitals are important here. It should look something like this:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">class</span> IndexController <span style="color: #000000; font-weight: bold;">extends</span> Zend_Controller_Action <span style="color: #009900;">&#123;</span>
&nbsp;
  <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>
&nbsp;
  <span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Again, we&#8217;re using the magic of the autoloader. While we&#8217;re in the directory, let&#8217;s also create an error controller that will tell us what we did wrong. The file will be called ErrorController.php</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">class</span> ErrorController <span style="color: #000000; font-weight: bold;">extends</span> Zend_Controller_Action <span style="color: #009900;">&#123;</span>
&nbsp;
  <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> errorAction<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$errors</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_getParam<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'error_handler'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$exception</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$errors</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">exception</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$exception</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getMessage</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;br /&gt;&lt;pre&gt;&quot;</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$exception</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getTraceAsString</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: #009900;">&#125;</span></pre></div></div>

<p>Now, we need to create some view scripts. You&#8217;ll need to create some folders. From BASE, you&#8217;ll want to create <code>/app/views/scripts/index</code> and <code>/app/views/scripts/error</code> &#8212; and then create index.phtml and error.phtml in the corresponding directories. <b>Note:</b> The name of the directory in scripts matches the CONTROLLER name, and the name of the .phtml file matches the ACTION name. So if we were to create an action in index called &#8216;about&#8217;, you would then create an &#8216;about.phtml&#8217; file in the /app/views/scripts/index directory. </p>
<p>Open up the index.phtml you just created and type &#8216;hello world&#8217;. Then open up the error.phtml file that you created and type &#8216;Oops, error!&#8217;. </p>
<p>Last but not least, we need an .htaccess file in BASE/html/.htaccess to tell Apache where to route things. Here&#8217;s the one I use: </p>
<pre>
Options +FollowSymLinks
IndexIgnore */*
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php
</pre>
<p>Now, the moment of truth &#8212; point your browser at your document root, and you should see &#8220;hello world&#8221;! If you got a blank screen, check your PHP error log. If you got a zend framework error printed to your screen, you know your error handler works..! Just figure out what went wrong and fix it. </p>
<p>Tomorrow we&#8217;re going to work with the database by adding some database boostrap logic to the front controller, and we&#8217;ll retrieve and display some rows with Zend_Db_Table. </p>
]]></content:encoded>
			<wfw:commentRss>http://www.karlkatzke.com/your-first-zend-framework-application-day-two/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Your First Zend Framework Application: Day One</title>
		<link>http://www.karlkatzke.com/your-first-zend-framework-application-day-one/</link>
		<comments>http://www.karlkatzke.com/your-first-zend-framework-application-day-one/#comments</comments>
		<pubDate>Mon, 28 Apr 2008 11:39:24 +0000</pubDate>
		<dc:creator>karlkatzke</dc:creator>
				<category><![CDATA[first application]]></category>
		<category><![CDATA[howto]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[webdev]]></category>
		<category><![CDATA[zend framework]]></category>
		<category><![CDATA[framework]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[zend]]></category>

		<guid isPermaLink="false">http://www.karlkatzke.com/?p=112</guid>
		<description><![CDATA[Over the next few days, I&#8217;ll be covering how to set up your first Zend Framework application using PHP and MySQL. First, some requirements. You should be comfortable on the command line or with your Subversion client. I&#8217;m writing from the point of view of someone who codes on a Linux or Mac machine using [...]]]></description>
			<content:encoded><![CDATA[<p>Over the next few days, I&#8217;ll be covering how to set up your first Zend Framework application using PHP and MySQL. </p>
<p>First, some requirements. You should be comfortable on the command line or with your Subversion client. I&#8217;m writing from the point of view of someone who codes on a Linux or Mac machine using vim. You will need to have PHP 5 installed on your server &#8212; this will not work unless you do. Second, I would recommend getting a VPS from a host like <a href="http://www.futurehosting.biz">Futurehosting</a> &#8212; for $20/mo, you get root access to your own machine, you can host as many sites or servers and have as many domain names as you want, and you get 350gb a month in transfer &#8212; I don&#8217;t think I&#8217;ve used <b>1gb</b> of transfer ever, and I do a ton of work with the server. I also Also, we&#8217;re going to assume you have access to a Subversion server. That&#8217;s just good practice, folks. Subversion hosts are very cheap &#8212; I usually use <a href="http://cvsdude.com/">CVSDude</a>. </p>
<p>Today we&#8217;re going to cover the folder structure, getting things into subversion, and locating the different files. Tuesday, we&#8217;ll cover the bootstrap and getting your index module and error module to show up. Wednesday, we&#8217;ll cover Zend_Db_Table_Abstract, Thursday we&#8217;ll cover Zend_Form, and Friday we&#8217;ll put it all together to get a user registration and login working. </p>
<p><b>Disclaimer</b>: I&#8217;m by no means a whiz kid with Zend Framework. ZF is unique among frameworks in that it gives you a toolset but does not enforce any conventions. The conventions I&#8217;m giving here are *my* conventions and may have nothing to do with the way you want to code. </p>
<p>Let&#8217;s dive right in.<span id="more-112"></span></p>
<div id="rightbox" style="width:340;float:right;font-size: 10px;margin-left: 10px; padding: 3px  ; border: 1px dotted black; background-color: #fefefe"><b>All Zend Framework Tutorials</b><br /><a href="http://www.karlkatzke.com/your-first-zend-framework-application-day-four/" title="View post Your First Zend Framework Application: Day Four">Your First Zend Framework Application: Day Four</a><br />
<a href="http://www.karlkatzke.com/your-first-zend-framework-application-day-thre/" title="View post Your First Zend Framework Application: Day Three">Your First Zend Framework Application: Day Three</a><br />
<a href="http://www.karlkatzke.com/your-first-zend-framework-application-day-two/" title="View post Your First Zend Framework Application: Day Two">Your First Zend Framework Application: Day Two</a><br />
<a href="http://www.karlkatzke.com/your-first-zend-framework-application-day-one/" title="View post Your First Zend Framework Application: Day One">Your First Zend Framework Application: Day One</a>
</div>
<p>Set up a directory to import into SVN. Your directory structure at import will look something like:</p>
<pre>
/home/myusername/projectfolder
                    /branches
                    /tags
                    /trunk
                           /app
                           /html
                           /lib
</pre>
<p>Now, let&#8217;s import that into a Subversion repository that you&#8217;ve already created somewhere else. Type:</p>
<pre>
[kkatzke@server]$ cd ~/projectfolder
[kkatzke@server]$ svn import ./ \
> http://www.cvsdude.org/svn/myusername/myproject \
> -m "Initial Import"</pre>
<p>(Those backslashes are included to indicate that the next line is also part of the command. I&#8217;m using them here because otherwise the text rides off into the sidebar. </p>
<p>Now delete the folders in your home directory that you created &#8211;<br /> <code>rm -rf /home/myusername/projectfolder</code>. </p>
<p>Let&#8217;s head over to where you want to actually have your application live, or at least where you want to do your development work. This will usually be /var/www&#8211; or wherever your webroot is. (You could actually place any of these files anywhere on the system, or on another system &#8212; but we&#8217;re trying to keep this simple here.) You&#8217;ll run this checkout command: <code>svn co http://cvsdude.org/svn/myusername/myproject/trunk .</code> &#8212; and note that last period, it&#8217;s important. The results will look something like this:</p>
<pre>A /app
A /html
A /lib</pre>
<p>Now you&#8217;ve got a working copy of your three directories that will make up the application. The first thing we need to do here is to get a copy of the Zend Framework to work with. SVN makes it easy to do this. From the directory you checked out to (you should type &#8216;ls&#8217; and see &#8220;app html lib&#8221;) Just run <code>svn propedit lib</code>, which should pop you into a blank text editor file. Type<br />
<code>Zend http://framework.zend.com/svn/framework/branch/release-1.5/library/Zend</code><br />
and save and close the file. When you&#8217;re back at the command prompt, just type<br />
<code>svn update</code><br />
and it will automatically pull in the Zend Framework into APP-ROOT/lib/Zend/ for you &#8230; although note that it specifically pulls in the lib/Zend folder, it does not pull in the incubator. That&#8217;s well outside of the scope of this beginner tutorial. </p>
<p>Last of all for today, you&#8217;ll need to add the rest of the directory structure for the application so that we can start with some code tomorrow. Here&#8217;s the way things should end up looking:</p>
<pre>
webroot/
        /app
              /config
              /controllers
              /forms
              /models
              /views
                      /scripts
                      /helpers
        /html
              /css
              /img
              /js
        /lib
              /Zend
</pre>
<p>When you&#8217;re done with all that, run <code>svn add</code> on all of the directories (use <code>svn status</code> to catch any you missed) and then run <code>svn commit</code> to save your changes to the repository. Congratulations! Tomorrow we&#8217;ll actually <b>do something</b> with all that work you did today.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.karlkatzke.com/your-first-zend-framework-application-day-one/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

