<?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>Simple MVC, a light PHP5 Framework</title>
	<atom:link href="http://simplemvc.berejeb.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://simplemvc.berejeb.com</link>
	<description></description>
	<lastBuildDate>Fri, 11 Feb 2011 01:04:33 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Simple MVC new version released</title>
		<link>http://simplemvc.berejeb.com/2010/11/simple-mvc-new-version-released/</link>
		<comments>http://simplemvc.berejeb.com/2010/11/simple-mvc-new-version-released/#comments</comments>
		<pubDate>Sun, 28 Nov 2010 03:38:51 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[News]]></category>

		<guid isPermaLink="false">http://simplemvc.berejeb.com/?p=144</guid>
		<description><![CDATA[The new version of Simple MVC is Proudly released! This version fixes many bugs and offers new functionnalities. Here is the Change log: Several Bug Fixes in the Core Package [...]]]></description>
			<content:encoded><![CDATA[<p>The new version of <strong><em><a href="/the-framework">Simple MVC</a></em></strong> is Proudly released! This version fixes many bugs and offers new functionnalities. Here is the Change log:</p>
<ul>
<li>Several Bug Fixes in the Core Package</li>
<li>Added Session Manager</li>
<li>Added Form Decorators</li>
<li>Added Access Handling</li>
<li>Added Configurable User Rights Manager</li>
<li>New FormElement Validators</li>
<li>Enhanced the MVC</li>
<li>Added a Debug Console</li>
<li>Added a default Demo Application</li>
</ul>
<p>Simple MVC Documentation will be tutorial based. As a first tutorial, you can check the &#8220;<strong><em><a href="http://simplemvc.berejeb.com/2010/11/builiding-an-iphone-app-with-simple-mvc-in-few-hours">Iphone Application With Simple MVC and jQuery Mobile</a></em></strong>&#8220;, which will show you how to develop in a few hour a complete RSS Feed. More tutorials are on the way to expose each time a functionnality or a feature of the Framework.</p>
<div id="attachment_147" class="wp-caption alignnone" style="width: 574px"><a href="http://simplemvc.berejeb.com/2010/11/builiding-an-iphone-app-with-simple-mvc-in-few-hours"><img class="size-full wp-image-147 " title="Simple MVC demo application" src="http://simplemvc.berejeb.com/wp-content/uploads/2010/11/Image-4.png" alt="Simple MVC demo application" width="564" height="496" /></a><p class="wp-caption-text">Iphone Application with Simple MVC and jquery Mobile</p></div>
]]></content:encoded>
			<wfw:commentRss>http://simplemvc.berejeb.com/2010/11/simple-mvc-new-version-released/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Building an Iphone Application with SimpleMVC in a few hours</title>
		<link>http://simplemvc.berejeb.com/2010/11/builiding-an-iphone-app-with-simple-mvc-in-few-hours/</link>
		<comments>http://simplemvc.berejeb.com/2010/11/builiding-an-iphone-app-with-simple-mvc-in-few-hours/#comments</comments>
		<pubDate>Sat, 27 Nov 2010 21:27:00 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Cookbook]]></category>

		<guid isPermaLink="false">http://simplemvc.berejeb.com/?p=123</guid>
		<description><![CDATA[Hello! Welcome to Simple MVC! In this  book, We will build an iphone web application using Simple MVC and jQuery mobile. The purpose of this application is  to allow users [...]]]></description>
			<content:encoded><![CDATA[<p>Hello! Welcome to Simple MVC! In this  book, We will build an<strong> iphone web application using Simple MVC and jQuery mobile</strong><em>. The purpose of this application is  to allow users to add and view RSS feeds. A demo of the application is available at : <a href="http://jquerymobile.demo.simplemvc.berejeb.com ">http://jquerymobile.demo.simplemvc.berejeb.com</a>. The code is Directly bundled with the <a href="https://github.com/bachkoutou/Simple-MVC">Simple MVC GitHub Repository</a> as a default application. So You just have to <a href="https://github.com/bachkoutou/Simple-MVC">grab the code from GitHub</a>.</em></p>
<p>Even if you see a bunch of steps in this cookbook, this will not take a lot from your time. We just split each functionnality in a separate page.</p>
<p><em>Here are the steps that we will follow :</em></p>
<ul>
<li><a href="http://simplemvc.berejeb.com/2010/11/installation-and-configuration/">Installation and configuration</a></li>
<li><a href="http://simplemvc.berejeb.com/2010/11/prepare-the-application-skeleton/">The application skeleton</a></li>
<li><a href="http://simplemvc.berejeb.com/2010/11/the-bootstrap-file/">The bootstrap file</a></li>
<li><a href="http://simplemvc.berejeb.com/2010/11/a-first-controller-action/">A first controller</a></li>
<li><a href="http://simplemvc.berejeb.com/2010/11/a-first-model-definition/">A first model definition</a></li>
<li><a href="http://simplemvc.berejeb.com/2010/11/a-first-view/">A first view</a></li>
<li><a href="http://simplemvc.berejeb.com/2010/11/the-business-configuration-files/">The business configuration files</a></li>
<li><a href="http://simplemvc.berejeb.com/2010/11/verifying-the-index-page/">Verifying the index page</a></li>
<li><a href="http://simplemvc.berejeb.com/2010/11/the-detail-page/">The detail page</a></li>
<li><a href="http://simplemvc.berejeb.com/2010/11/the-add-page/">The add page</a></li>
</ul>
<p>So lets start with the <a href="http://simplemvc.berejeb.com/2010/11/introduction/">Installation</a>!</p>
]]></content:encoded>
			<wfw:commentRss>http://simplemvc.berejeb.com/2010/11/builiding-an-iphone-app-with-simple-mvc-in-few-hours/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>The add page</title>
		<link>http://simplemvc.berejeb.com/2010/11/the-add-page/</link>
		<comments>http://simplemvc.berejeb.com/2010/11/the-add-page/#comments</comments>
		<pubDate>Sat, 27 Nov 2010 20:50:31 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Cookbook]]></category>

		<guid isPermaLink="false">http://simplemvc.berejeb.com/?p=81</guid>
		<description><![CDATA[We need a form to implement the add page. To get that done, we will make use of the Simple MVC forms. Let&#8217;s start as always, by the controller add [...]]]></description>
			<content:encoded><![CDATA[<p>We need a form to implement the add page. To get that done, we will make use of the Simple MVC forms. Let&#8217;s start as always, by the controller add action :</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p81code5'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p815"><td class="code" id="p81code5"><pre class="php" style="font-family:monospace;">    <span style="color: #009933; font-style: italic;">/**
     * add Action
     *
     */</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> addAction<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;">model</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">bind</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Request</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;">model</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">checkin</span><span style="color: #009900;">&#40;</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;">form</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> FeedForm<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Feed'</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;">form</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">initFromModel</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">model</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #666666; font-style: italic;">// Handle eventual errors</span>
        <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Request</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'errors'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;</span>amp<span style="color: #339933;">;&amp;</span>amp<span style="color: #339933;">;</span> <span style="color: #990000;">is_array</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Request</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'errors'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
        <span style="color: #009900;">&#123;</span>
            <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">view</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">form</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setErrors</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Request</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'errors'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>The add action will use a FeedForm that we will create later. we can directly init the form the model using the initFromModel method. This will create text fields directly from the model properties, and take care of not displaying the ids.<br />
Since the add method will also handle the errors if the informations are not filled for example, we need to add a test on the errors request variable and set those one to the view.<br />
We will create a new form under business/front/forms/FeedForm.php :</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p81code6'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p816"><td class="code" id="p81code6"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">class</span> FeedForm <span style="color: #000000; font-weight: bold;">extends</span> Form
<span style="color: #009900;">&#123;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>That&#8217;s all what we need to set for the form. It will work because the initFromModel will create dynamically the form elements. However, we can create  independent forms with fields that are not binded to the model form. We will cover that later in a separate tutorial concerning Forms.<br />
Lets code the view part now, under the folder : business/front/views/Feed/add.php add the following code.</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p81code7'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p817"><td class="code" id="p81code7"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">languages</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'add_feed'</span><span style="color: #009900;">&#93;</span>?<span style="color: #339933;">&amp;</span>gt<span style="color: #339933;">;&amp;</span>lt<span style="color: #339933;">;/</span>h3<span style="color: #339933;">&amp;</span>gt<span style="color: #339933;">;&amp;</span>lt<span style="color: #339933;">;</span>?php
<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">form</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">render</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>That&#8217;s all we need to do in the view, the render method of the view will handle all the magic. again, we can customize the form rendering using decoractors. This will be also covered in the Form section later.</p>
<p>The add page lacks only one thing. The part that will verify and save the feed. To implement this, we need to code the saveAction :</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p81code8'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p818"><td class="code" id="p81code8"><pre class="php" style="font-family:monospace;">&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> saveAction<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;">model</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">bind</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Request</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$form</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> FeedForm<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Feed'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$form</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">initFromModel</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">model</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;">$form</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">validate</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: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">model</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">save</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;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Router</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">redirect</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'index'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'Feed'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">language</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'redirect'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'element_saved'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> CoreView<span style="color: #339933;">::</span><span style="color: #004000;">MESSAGE_TYPE_SUCCESS</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
            <span style="color: #b1b100;">else</span>
            <span style="color: #009900;">&#123;</span>
                <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Router</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">redirect</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'index'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'Feed'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">language</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'redirect'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'element_not_saved'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> CoreView<span style="color: #339933;">::</span><span style="color: #004000;">MESSAGE_TYPE_ERROR</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
        <span style="color: #009900;">&#125;</span>
        <span style="color: #b1b100;">else</span>
        <span style="color: #009900;">&#123;</span>
            <span style="color: #000088;">$params</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array_merge</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: #339933;">=&gt;</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">model</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">id</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'errors'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$form</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getErrors</span><span style="color: #009900;">&#40;</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;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Router</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">redirect</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'add'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'Feed'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">language</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'redirect'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'element_not_saved'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> CoreView<span style="color: #339933;">::</span><span style="color: #004000;">MESSAGE_TYPE_ERROR</span><span style="color: #339933;">,</span> <span style="color: #000088;">$params</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>The save action will first bind the contents of the model from the Request. this method basically fills the instance properties from the Request. After, we instanciate a new FeedForm and we initialise it from the model. To validate the form, we simply call the $form->validate() method. The framework will verify that all the validators are satisfied. By default, Simple MVC adds a default validators to all properties which is a NotEmpty validator. This is what makes you have required fields.<br />
If the form is validated and the model is saved, we redirect to the index action with  a success message, otherwise, we redirect to the add page with the errors we got from the $form->getErrors() method.<br />
That&#8217;s all! You can try your form now. </p>
<p>These few steps show how to do stuff with Simple MVC. Of course the stuff we explored here is basic. For more details, you can see the API Documentation or the other specialised tutorials. We are continually updating those section to expose what can be done with the framework.</p>
]]></content:encoded>
			<wfw:commentRss>http://simplemvc.berejeb.com/2010/11/the-add-page/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>The detail page</title>
		<link>http://simplemvc.berejeb.com/2010/11/the-detail-page/</link>
		<comments>http://simplemvc.berejeb.com/2010/11/the-detail-page/#comments</comments>
		<pubDate>Sat, 27 Nov 2010 20:49:56 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Cookbook]]></category>

		<guid isPermaLink="false">http://simplemvc.berejeb.com/?p=79</guid>
		<description><![CDATA[To implement the detail page, we will basically redo what we have done for the index page. One thing we will not redo it, however, is the template section. This [...]]]></description>
			<content:encoded><![CDATA[<p>To implement the detail page, we will basically redo what we have done for the index page. One thing we will not redo it, however, is the template section. This will work for all the views.<br />
So, let&#8217;s start with the controller and add the detail action.</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p79code12'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p7912"><td class="code" id="p79code12"><pre class="php" style="font-family:monospace;">    <span style="color: #009933; font-style: italic;">/**
     * Detail action
     *
     */</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> detailAction<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Request</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'id'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">||</span> <span style="color: #339933;">!</span><span style="color: #990000;">is_numeric</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Request</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'id'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</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;">Router</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">redirect</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'index'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">model</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">id</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Request</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'id'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">model</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">checkin</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: #339933;">!</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">model</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">id</span><span style="color: #009900;">&#41;</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;">model</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">id</span><span style="color: #009900;">&#41;</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;">Router</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">redirect</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'index'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
        <span style="color: #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;">feed</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> stdClass<span style="color: #009900;">&#40;</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;">feed</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">name</span>  <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">model</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">name</span><span style="color: #339933;">;</span>
        <span style="color: #666666; font-style: italic;">// get the rss feeds</span>
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getFeedInfos</span><span style="color: #009900;">&#40;</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;">feed</span><span style="color: #339933;">,</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">model</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">url</span><span style="color: #339933;">,</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">model</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">itemsNumber</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>The detail Action is supposed to get a feed id from the request, sot before getting the feeds, we verify if everything is okay with that parameter, and we also check if there is a<br />
model corresponding to that id. This is done by affecting the id to the model and by calling the checkin method. This method will fill the object properties with the relative field if the id exists in the database. If the record is not found, the model properties remain empty and the id property we previously affected will be cleared also. That&#8217;s why we are checking on the id after the checkin call.<br />
If the id does not exist, using the Router object, we can redirect the user using the redirect method. If the record exists, we will get the feed from the private method getFeedInfos to which we give three parameters: $this->view->feed: this will be where the feeds are stored. the url from the model, and the items number we want to retreive.</p>
<p>So let&#8217;s code that method :</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p79code13'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p7913"><td class="code" id="p79code13"><pre class="php" style="font-family:monospace;">    <span style="color: #009933; font-style: italic;">/**
     * Returns a list of elements from an rss Feed
     *
     * @param  mixed  $url
     * @param  int    $itemsNumber
     * @return array the rss items
     */</span>
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">function</span> getFeedInfos<span style="color: #009900;">&#40;</span><span style="color: #000088;">$feed</span><span style="color: #339933;">,</span> <span style="color: #000088;">$url</span><span style="color: #339933;">,</span> <span style="color: #000088;">$itemsNumber</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$rss</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getRSS</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$url</span><span style="color: #339933;">,</span> <span style="color: #000088;">$itemsNumber</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$feed</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">title</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$rss</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">channel</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">title</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$feed</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">description</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$rss</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">channel</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">description</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$feed</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">link</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$rss</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">channel</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">link</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$feed</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">lastUpdated</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$rss</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">channel</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">lastBuildDate</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$feed</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">image</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$rss</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">channel</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">image</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$feed</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">items</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: #000088;">$i</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
        <span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$rss</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">channel</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">item</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$item</span><span style="color: #009900;">&#41;</span>
        <span style="color: #009900;">&#123;</span>
            <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$i</span> <span style="color: #339933;">==</span> <span style="color: #000088;">$itemsNumber</span><span style="color: #009900;">&#41;</span> <span style="color: #b1b100;">break</span><span style="color: #339933;">;</span>
            <span style="color: #000088;">$feed</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">items</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$item</span><span style="color: #339933;">;</span>
            <span style="color: #000088;">$i</span><span style="color: #339933;">++;</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #009933; font-style: italic;">/**
     * gets a feed
     *
     * @param  mixed  $url
     * @param  int    $itemsNumber Optional, defaults to 5.
     * @return SimpleXMLElement the element
     */</span>
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">function</span> getRSS<span style="color: #009900;">&#40;</span><span style="color: #000088;">$url</span><span style="color: #339933;">,</span> <span style="color: #000088;">$itemsNumber</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">5</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$feedKey</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'simplemvc_cache_feeds_list_'</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$url</span><span style="color: #339933;">;</span>
        <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">CacheManager</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">exists</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$feedKey</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
        <span style="color: #009900;">&#123;</span>
            <span style="color: #000088;">$client</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> CurlClient<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #000088;">$client</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setUrl</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$url</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #000088;">$client</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setReturnTransfer</span><span style="color: #009900;">&#40;</span><span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #000088;">$client</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setAsGet</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #000088;">$feedRaw</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$client</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">call</span><span style="color: #009900;">&#40;</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;">CacheManager</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">set</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$feedKey</span><span style="color: #339933;">,</span> <span style="color: #000088;">$feedRaw</span><span style="color: #339933;">,</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Config</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'general'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'rss'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'ttl'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #000088;">$feeds</span> <span style="color: #339933;">=</span> <span style="color: #990000;">simplexml_load_string</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$feedRaw</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
        <span style="color: #b1b100;">else</span>
        <span style="color: #009900;">&#123;</span>
            <span style="color: #000088;">$feeds</span> <span style="color: #339933;">=</span> <span style="color: #990000;">simplexml_load_string</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">CacheManager</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">get</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$feedKey</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
        <span style="color: #b1b100;">return</span> <span style="color: #000088;">$feeds</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Okay, time to explain what we did. The getFeedInfo method will get the information from the getRSS method and fill only the information we need in the view from the result. nothing more to say for that method. However, it is in the getRSS method where things are done.<br />
This method uses a cache mechanism. to implement that, we need to define a unique cache key : $feedKey. To check if there is the rss has been already checked before we use the exists method of the CacheManager. if it is the case, we use the get method to get the content.<br />
If this is the first time we ask for this RSS, we will do a curl call to get the contents and store them in the cache by the occasion. We make use of the CurlClient class to get the contents. setURl, setReturnTransfer, setAsGet and call are self explanatory. Next, the CacheManager->set method stores the entry in the cache, and we affect  a SimpleXMLElement to the $feeds variable.<br />
We will do some refactoring later on to get out the CurlClient instanciation from the controller. if We want a unit testable code, we should not have instanciations directly in the controller. The CurlClient will be moved to the Container. we will cover that later.<br />
This is all we need to do for the controller, Let&#8217;s code the view part. open a new file business/front/views/Feed/detail.php and add the following:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p79code14'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p7914"><td class="code" id="p79code14"><pre class="php" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>div <span style="color: #000000; font-weight: bold;">class</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;ui-grid-a&quot;</span><span style="color: #339933;">&gt;</span>
    <span style="color: #000000; font-weight: bold;">&lt;?php</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;">feed</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">image</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">url</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
    <span style="color: #339933;">&lt;</span>div <span style="color: #000000; font-weight: bold;">class</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;ui-block-a&quot;</span><span style="color: #339933;">&gt;</span>
        <span style="color: #339933;">&lt;</span>a href<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;&lt;?php echo <span style="color: #006699; font-weight: bold;">$this-&gt;feed</span>-&gt;link?&gt;&quot;</span><span style="color: #339933;">&gt;</span>
            <span style="color: #339933;">&lt;</span>img src<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;&lt;?php echo <span style="color: #006699; font-weight: bold;">$this-&gt;feed</span>-&gt;image-&gt;url?&gt;&quot;</span> alt<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;&lt;?php echo <span style="color: #006699; font-weight: bold;">$this-&gt;feed</span>-&gt;image-&gt;title?&gt;&quot;</span> title<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;&lt;?php echo <span style="color: #006699; font-weight: bold;">$this-&gt;feed</span>-&gt;image-&gt;title?&gt;&quot;</span><span style="color: #339933;">/&gt;</span>
        <span style="color: #339933;">&lt;/</span>a<span style="color: #339933;">&gt;</span>
    <span style="color: #339933;">&lt;/</span>div<span style="color: #339933;">&gt;</span>
    <span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
    <span style="color: #339933;">&lt;</span>div <span style="color: #000000; font-weight: bold;">class</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;ui-block-b&quot;</span><span style="color: #339933;">&gt;</span>
    <span style="color: #339933;">&lt;</span>h3<span style="color: #339933;">&gt;</span>
        <span style="color: #339933;">&lt;</span>a href<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;&lt;?php echo <span style="color: #006699; font-weight: bold;">$this-&gt;feed</span>-&gt;link?&gt;&quot;</span><span style="color: #339933;">&gt;</span>
            <span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">feed</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">title</span><span style="color: #000000; font-weight: bold;">?&gt;</span>
        <span style="color: #339933;">&lt;/</span>a<span style="color: #339933;">&gt;&lt;</span>br<span style="color: #339933;">/&gt;</span>
        <span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">languages</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'last_updated'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">' : '</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">feed</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">lastUpdated</span><span style="color: #000000; font-weight: bold;">?&gt;</span>
    <span style="color: #339933;">&lt;/</span>h3<span style="color: #339933;">&gt;</span>
    <span style="color: #339933;">&lt;/</span>div<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;/</span>div<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>div data<span style="color: #339933;">-</span>role<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;collapsible&quot;</span><span style="color: #339933;">&gt;</span>
    <span style="color: #339933;">&lt;</span>h3<span style="color: #339933;">&gt;</span><span style="color: #000000; font-weight: bold;">&lt;?</span>php <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">languages</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'you_are_reading_feed'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">' : '</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">feed</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">name</span> <span style="color: #000000; font-weight: bold;">?&gt;</span><span style="color: #339933;">&lt;/</span>h3<span style="color: #339933;">&gt;</span>
    <span style="color: #000000; font-weight: bold;">&lt;?php</span>
    <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">count</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">feed</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">items</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">?&gt;</span><span style="color: #339933;">&lt;</span>div <span style="color: #000000; font-weight: bold;">class</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;feed_element&quot;</span><span style="color: #339933;">&gt;</span><span style="color: #000000; font-weight: bold;">&lt;?</span>php <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">languages</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'no_feed_entries'</span><span style="color: #009900;">&#93;</span><span style="color: #000000; font-weight: bold;">?&gt;</span><span style="color: #339933;">&lt;/</span>div<span style="color: #339933;">&gt;</span><span style="color: #000000; font-weight: bold;">&lt;?</span>php
    <span style="color: #009900;">&#125;</span>
    <span style="color: #b1b100;">else</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">feed</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">items</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$item</span><span style="color: #009900;">&#41;</span>
        <span style="color: #009900;">&#123;</span>
            <span style="color: #000000; font-weight: bold;">?&gt;</span>
                <span style="color: #339933;">&lt;</span>div <span style="color: #000000; font-weight: bold;">class</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;feed_element&quot;</span><span style="color: #339933;">&gt;</span>
                <span style="color: #339933;">&lt;</span>h4<span style="color: #339933;">&gt;&lt;</span>a href<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;&lt;?php echo <span style="color: #006699; font-weight: bold;">$item-&gt;link</span>?&gt;&quot;</span><span style="color: #339933;">&gt;</span><span style="color: #000000; font-weight: bold;">&lt;?</span>php <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$item</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">title</span><span style="color: #000000; font-weight: bold;">?&gt;</span><span style="color: #339933;">&lt;/</span>a<span style="color: #339933;">&gt;&lt;/</span>h4<span style="color: #339933;">&gt;</span>
                <span style="color: #339933;">&lt;</span>p<span style="color: #339933;">&gt;</span><span style="color: #000000; font-weight: bold;">&lt;?</span>php <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$item</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">description</span> <span style="color: #000000; font-weight: bold;">?&gt;</span><span style="color: #339933;">&lt;/</span>p<span style="color: #339933;">&gt;</span>
                <span style="color: #339933;">&lt;/</span>div<span style="color: #339933;">&gt;</span>
                <span style="color: #000000; font-weight: bold;">&lt;?php</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #000000; font-weight: bold;">?&gt;</span>
<span style="color: #339933;">&lt;/</span>div<span style="color: #339933;">&gt;</span></pre></td></tr></table></div>

<p>This follows same rules, looping through items to display the items information, using the language variables when needed. We already added the languages for the feed.detail page in the business/front/conf/languages.en.ini file.<br />
Finished : Let&#8217;s test the page!, click on a feed and you should see the details with a nice sliding effect.<br />
<a href="http://simplemvc.berejeb.com/2010/11/the-add-page/">Let&#8217;s move forward to add an action that adds a feed</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://simplemvc.berejeb.com/2010/11/the-detail-page/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Verifying the index page</title>
		<link>http://simplemvc.berejeb.com/2010/11/verifying-the-index-page/</link>
		<comments>http://simplemvc.berejeb.com/2010/11/verifying-the-index-page/#comments</comments>
		<pubDate>Sat, 27 Nov 2010 20:49:20 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Cookbook]]></category>

		<guid isPermaLink="false">http://simplemvc.berejeb.com/?p=77</guid>
		<description><![CDATA[At this step, all is done to get the index action showing the list. Make sure you pointed your virtual host to the www directory. the conf directory contains a [...]]]></description>
			<content:encoded><![CDATA[<p>At this step, all is done to get the index action showing the list. Make sure you pointed your virtual host to the www directory. the conf directory contains a virtual host sample that allows you to do that. Here is the steps to do that :</p>
<pre>
<div id="_mcePaste">$ sudo cp conf/virtual-host-sample.conf /etc/apache2/sites-enabed/simplemvc.conf</div>
<div id="_mcePaste">$sudo vi /etc/apache2/sites-enabed/simplemvc.conf</div>
<div id="_mcePaste">// put your ServerName and the path to the DocumentRoot and Directory</div>
<div id="_mcePaste">&lt;VirtualHost *:80&gt;</div>
<div id="_mcePaste">    ServerName www.simplemvc.dev</div>
<div id="_mcePaste">    DocumentRoot /var/www/simpleMVC/www</div>
<div id="_mcePaste">    &lt;Directory /var/www/simpleMVC/www&gt;</div>
<div id="_mcePaste">      AllowOverride All</div>
<div id="_mcePaste">      Order allow,deny</div>
<div id="_mcePaste">      allow from all</div>
<div id="_mcePaste">    &lt;/Directory&gt;</div>
<div id="_mcePaste">&lt;/VirtualHost&gt;</div>
<div id="_mcePaste">// save the file and exit.</div>
<div id="_mcePaste">$ sudo vi /etc/hosts</div>
<div id="_mcePaste">// add the following line to your hosts file</div>
<div id="_mcePaste">127.0.0.1 www.simplemvc.dev</div>
<div id="_mcePaste">// save the file and exit</div>

<span style="font-family: Georgia, 'Times New Roman', 'Bitstream Charter', Times, serif; line-height: 19px; white-space: normal; font-size: 13px;">Type now http://www.simplemvc.dev/?controller=Feed&amp;action=index you should see a page like : <a href="http://jquerymobile.demo.simplemvc.berejeb.com">http://jquerymobile.demo.simplemvc.berejeb.com</a>!</span></pre>
<p>Pretty cool no?<br />
A question that I see coming is  : why should I add /?controller=Feed&amp;action=index if This is my first page? You are absolutely right. This can be solved either by a rewrite rule, or by 2 lines added in the bootstrap file. Let&#8217;s add them right now. Open the www/index.php file and add the following as the first lines in your try block :</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p77code16'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p7716"><td class="code" id="p77code16"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$_REQUEST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'controller'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> Toolbox<span style="color: #339933;">::</span><span style="color: #004000;">getArrayParameter</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_REQUEST</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'controller'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'Feed'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$_REQUEST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'action'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> Toolbox<span style="color: #339933;">::</span><span style="color: #004000;">getArrayParameter</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_REQUEST</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'action'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'index'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>This should add a default action and controller names if nothing is provided from the request.<br />
You can see the rendering on the iphone, it is really good.<br />
This is all for the indexAction. When clicking on the feed title, we are redirected to the detail page, <a href="http://simplemvc.berejeb.com/2010/11/the-detail-page/">which we will start implementing right now</a>!</p>
]]></content:encoded>
			<wfw:commentRss>http://simplemvc.berejeb.com/2010/11/verifying-the-index-page/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>The business configuration files</title>
		<link>http://simplemvc.berejeb.com/2010/11/the-business-configuration-files/</link>
		<comments>http://simplemvc.berejeb.com/2010/11/the-business-configuration-files/#comments</comments>
		<pubDate>Sat, 27 Nov 2010 20:48:40 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Cookbook]]></category>

		<guid isPermaLink="false">http://simplemvc.berejeb.com/?p=75</guid>
		<description><![CDATA[In Simple MVC, the business configuration files are splitted as follow : ?View Code SHELL. &#124;-- business &#124;-- conf &#124; `-- apps.ini.changeme `-- front &#124;-- conf &#124; &#124;-- access.ini &#124; [...]]]></description>
			<content:encoded><![CDATA[<p>In Simple MVC, the business configuration files are splitted as follow :</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p75code21'); return false;">View Code</a> SHELL</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p7521"><td class="code" id="p75code21"><pre class="shell" style="font-family:monospace;">.
|-- business
      |-- conf
      |   `-- apps.ini.changeme
      `-- front
          |-- conf
          |   |-- access.ini
          |   |-- front.ini.changeme
          |   |-- languages.en.ini
          |   `-- user_rights.ini</pre></td></tr></table></div>

<p>the business/conf folder contains a file named apps.ini.changeme. This file specifies common configuration for the business layer, it should be renamed to apps.ini and customized. Here is its content :</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p75code22'); return false;">View Code</a> SHELL</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p7522"><td class="code" id="p75code22"><pre class="shell" style="font-family:monospace;">[database]
host = localhost;
user = *****;
password = *****;
database = *****;
type = mysql;
&nbsp;
[template]
URL = http://simplemvc.berejeb.com/;
&nbsp;
[controller]
&nbsp;
[model]
&nbsp;
[view]
autorender_template = 1;
&nbsp;
[cache]
;allowed types : Array, File, APC
type = File;
prefix = simplemvc;
directory = /tmp;</pre></td></tr></table></div>

<p>So as you notice, the file contains global sections like database, which handles the database connection params, template, controller,  model and view sections, and cache section. Those can be a global placeholder for your common configurations across your applications.</p>
<p>You can then override those sections per application. For each Application you write, you must add a <application-name>.ini file under business/<application-name>/conf/. So in our case, business/front/conf/front.ini. by default you have a  front.ini.changeme for the module front. I&#8217;ve already put the configuration by default in this file :</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p75code23'); return false;">View Code</a> SHELL</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p7523"><td class="code" id="p75code23"><pre class="shell" style="font-family:monospace;">[general]
application.session.checkFrequency = &quot;300000&quot;;
images.destination_dir = &quot;/the/path/to/your/images/uploads/&quot;;
images.destination_url = &quot;/images/uploads/&quot;;
rss.ttl = 10000;</pre></td></tr></table></div>

<p>You have to copy that file under front.ini and from there, you can override the global conf file. for example, if you have two applications that are dealing with different database connections, you can overrite the database section to sepecify the connection params for each application.</p>
<p>Also, remember in the boostrap file, we had some lines of code that were dealing with access. The helper was actually looking for the acces.ini configuration file  ccess.ini :<br />
This file indicates if each action should be public or protected.</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p75code24'); return false;">View Code</a> INI</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p7524"><td class="code" id="p75code24"><pre class="ini" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">; Access Config file : </span>
<span style="color: #666666; font-style: italic;">; 0 - public</span>
<span style="color: #666666; font-style: italic;">; 1 - protected</span>
Feed.index <span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;"> 0</span><span style="color: #666666; font-style: italic;">;</span>
Feed.detail <span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;"> 0</span><span style="color: #666666; font-style: italic;">;</span>
Feed.add <span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;"> 1</span><span style="color: #666666; font-style: italic;">;</span></pre></td></tr></table></div>

<p>This is basically what we need to get the config working.<br />
<a href="http://simplemvc.berejeb.com/2010/11/verifying-the-index-page/">Move on to the next section, let&#8217;s take a look at our first page!</a></p>
]]></content:encoded>
			<wfw:commentRss>http://simplemvc.berejeb.com/2010/11/the-business-configuration-files/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>A first view</title>
		<link>http://simplemvc.berejeb.com/2010/11/a-first-view/</link>
		<comments>http://simplemvc.berejeb.com/2010/11/a-first-view/#comments</comments>
		<pubDate>Sat, 27 Nov 2010 20:48:05 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Cookbook]]></category>

		<guid isPermaLink="false">http://simplemvc.berejeb.com/?p=73</guid>
		<description><![CDATA[The Simple MVC views follow the two-step view pattern. This allows you to specify a global container page in which you can specify your head page, your foot page and [...]]]></description>
			<content:encoded><![CDATA[<p>The Simple MVC views follow the two-step view pattern. This allows you to specify a global container page in which you can specify your head page, your foot page and may be some lateral columns. In the main part of your page, you will display each time the contents of your specific action (index, detail, add etc.).<br />
The views also deal with JavaScript and CSS libraries. In Simple MVC, the view is also a class which is  placed under business/{your-module-application}/views/ . Since the view has to deal with templates and partial views, we have some other files to store the template folder and the view folder. We call a template the global container page, and view the partial specific view.<br />
Since the templates will be used by many views, they are pretty independent, so they are placed under business/{your-module-application}/templates.<br />
Here is a structure of the files we should have at the end:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p73code31'); return false;">View Code</a> SHELL</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p7331"><td class="code" id="p73code31"><pre class="shell" style="font-family:monospace;">$ tree business/front/views/
views
|-- Feed
|   |-- add.php
|   |-- detail.php
|   `-- index.php
|-- FeedView.php
|-- Main
|   |-- footer.php
|   `-- header.php
`-- MainView.php
$ tree business/front/templates/
templates
`-- default.php</pre></td></tr></table></div>

<p>The views folder contains Two sections: Feed and Main, each one is composed by a View.php file and a  folder. Actually, the Feed.php file will handle the view class itself, whereas the  folder wil contain the html related to each action.<br />
The Main section is a common section which is extended by the other views. this allows reusing common calls, script calls, css calls, common html code etc.<br />
You will understand better with an example. So let&#8217;s write our index view:<br />
First, we will create our FeedView and MainViews classes under views (placed under business/front/views/FeedView.php and business/front/views/FeedView.php)</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p73code32'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p7332"><td class="code" id="p73code32"><pre class="php" style="font-family:monospace;"><span style="color: #009933; font-style: italic;">/**
 * Feed Front View
 */</span>
<span style="color: #000000; font-weight: bold;">class</span> FeedView <span style="color: #000000; font-weight: bold;">extends</span> MainView
<span style="color: #009900;">&#123;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">class</span> MainView <span style="color: #000000; font-weight: bold;">extends</span> CoreView
<span style="color: #009900;">&#123;</span>
    <span style="color: #009933; font-style: italic;">/**
     * index Action
     *
     */</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> alwaysAction<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;">addJs</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'/scripts/jquery-1.4.4.min.js'</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;">enableJQueryMobile</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #009933; font-style: italic;">/**
     * Adds the js and css for the jqueryMobile Framework
     *
     */</span>
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">function</span> enableJQueryMobile<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;">addCss</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'/scripts/jquery.mobile-1.0a2/jquery.mobile-1.0a2.min.css'</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;">addJs</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'/scripts/jquery.mobile-1.0a2/jquery.mobile-1.0a2.min.js'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Since all the code we need to have is a common code untill now, we wrote it in the MainView. Basically, we just need to include our Javascript and CSS needed. In this case, and since we are using jQueryMobile as a framework for our iphone application, all we need to do is to include the  javascriot for the jQuery Framework, and the Javascript and CSS for <a href="http://jquerymobile.org">jQueryMobile</a>.<br />
For purpose of simplicity, the jQuery Mobile is directly bundled in the default www folder of Simple MVC. You can change the scripts and styles if a new version has been released.</p>
<p>Next step is to write our first template. Usually, we need to do this once for every module, unless you want different templates for your sections. so We will add a default template under business/front/templates/default.php:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p73code33'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p7333"><td class="code" id="p73code33"><pre class="php" style="font-family:monospace;"><span style="color: #339933;">&lt;!</span>DOCTYPE html <span style="color: #000000; font-weight: bold;">PUBLIC</span> <span style="color: #0000ff;">&quot;-//W3C//DTD XHTML 1.0 Transitional//EN&quot;</span> <span style="color: #0000ff;">&quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&quot;</span><span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>html xmlns<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;http://www.w3.org/1999/xhtml&quot;</span><span style="color: #339933;">&gt;</span>
    <span style="color: #339933;">&lt;</span>head<span style="color: #339933;">&gt;</span>
        <span style="color: #339933;">&lt;</span>meta http<span style="color: #339933;">-</span>equiv<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;Content-Type&quot;</span> content<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;text/html; charset=utf-8&quot;</span> <span style="color: #339933;">/&gt;</span>
        <span style="color: #339933;">&lt;</span>title<span style="color: #339933;">&gt;</span><span style="color: #000000; font-weight: bold;">&lt;?</span>php <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">languages</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'title'</span><span style="color: #009900;">&#93;</span><span style="color: #000000; font-weight: bold;">?&gt;</span><span style="color: #339933;">&lt;/</span>title<span style="color: #339933;">&gt;</span>
       <span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">renderCss</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><span style="color: #000000; font-weight: bold;">?&gt;</span>
       <span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">renderJs</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><span style="color: #000000; font-weight: bold;">?&gt;</span>
    <span style="color: #339933;">&lt;/</span>head<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>body<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>div data<span style="color: #339933;">-</span>role<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;page&quot;</span><span style="color: #339933;">&gt;</span>
    <span style="color: #000000; font-weight: bold;">&lt;?php</span>
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">render</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'header'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'Main'</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;">renderMessages</span><span style="color: #009900;">&#40;</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;">main</span><span style="color: #009900;">&#40;</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;">render</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'footer'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'Main'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">?&gt;</span>
<span style="color: #339933;">&lt;/</span>div<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;/</span>body<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;/</span>html<span style="color: #339933;">&gt;</span></pre></td></tr></table></div>

<p>Not too long. Let&#8217;s explain :<br />
- in the head section, to display the title, we used $this->languages['title'], this allows you to have a multilingual application. Later on, we will have to fill a language file with the needed variables. Next in the head section, we have to call the renderCss and renderJs methods to get the previously pushed css and js code in the view.<br />
- in the body section, the first php line uses the method render. this allows actually to call specific blocks in the view, here we are calling the header block and the footer block.<br />
Thos blocks are actually under the Main view (see the file hierarchy above). The main() method will get the specific view to display it in the middle of the page.</p>
<p>Allright, what we are missing to get the work complete ? I&#8217;ll tell you:<br />
- the partials (header, footer, feed index)<br />
- the language file<br />
Let&#8217;s start to write our header file, this one has to be under business/front/views/Main/header.php</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p73code34'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p7334"><td class="code" id="p73code34"><pre class="php" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>div data<span style="color: #339933;">-</span>role<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;header&quot;</span><span style="color: #339933;">&gt;</span>
    <span style="color: #339933;">&lt;</span>h1<span style="color: #339933;">&gt;</span><span style="color: #000000; font-weight: bold;">&lt;?</span>php <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">languages</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'title'</span><span style="color: #009900;">&#93;</span><span style="color: #000000; font-weight: bold;">?&gt;</span><span style="color: #339933;">&lt;/</span>h1<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;/</span>div<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>div data<span style="color: #339933;">-</span>role<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;content&quot;</span><span style="color: #339933;">&gt;&lt;!--</span>begin content <span style="color: #339933;">--&gt;</span>
    <span style="color: #339933;">&lt;</span>div id<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;jqm-homeheader&quot;</span><span style="color: #339933;">&gt;</span>
        <span style="color: #339933;">&lt;</span>h1<span style="color: #339933;">&gt;</span><span style="color: #000000; font-weight: bold;">&lt;?</span>php <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">languages</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'title'</span><span style="color: #009900;">&#93;</span><span style="color: #000000; font-weight: bold;">?&gt;</span><span style="color: #339933;">&lt;/</span>h1<span style="color: #339933;">&gt;</span>
        <span style="color: #339933;">&lt;</span>p<span style="color: #339933;">&gt;</span><span style="color: #000000; font-weight: bold;">&lt;?</span>php <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">languages</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'description'</span><span style="color: #009900;">&#93;</span><span style="color: #000000; font-weight: bold;">?&gt;</span><span style="color: #339933;">&lt;/</span>p<span style="color: #339933;">&gt;</span>
    <span style="color: #339933;">&lt;/</span>div<span style="color: #339933;">&gt;</span></pre></td></tr></table></div>

<p>Notice always here that we are using the languages to display our text. Also notice the attributes and the specific classes of the jQueryMobile framework. Those will allow it to display correctly the styles and effects under iphone. This is what I like in this framework, it is the progressive enhancement method!<br />
Anyway <img src='http://simplemvc.berejeb.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' />  lets write our footer file under business/front/views/Main/footer.php</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p73code35'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p7335"><td class="code" id="p73code35"><pre class="php" style="font-family:monospace;"><span style="color: #339933;">&lt;/</span>div<span style="color: #339933;">&gt;&lt;!--</span> <span style="color: #990000;">end</span> content <span style="color: #339933;">--&gt;</span>
<span style="color: #339933;">&lt;</span>div data<span style="color: #339933;">-</span>role<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;footer&quot;</span> <span style="color: #000000; font-weight: bold;">class</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;ui-bar&quot;</span><span style="color: #339933;">&gt;</span>
    <span style="color: #339933;">&lt;</span>div data<span style="color: #339933;">-</span>role<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;controlgroup&quot;</span> data<span style="color: #339933;">-</span>type<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;horizontal&quot;</span><span style="color: #339933;">&gt;</span>
    <span style="color: #339933;">&lt;</span>a href<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;/&quot;</span> data<span style="color: #339933;">-</span>role<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;button&quot;</span> data<span style="color: #339933;">-</span>icon<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;home&quot;</span><span style="color: #339933;">&gt;</span><span style="color: #000000; font-weight: bold;">&lt;?</span>php <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">languages</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'home'</span><span style="color: #009900;">&#93;</span><span style="color: #000000; font-weight: bold;">?&gt;</span><span style="color: #339933;">&lt;/</span>a<span style="color: #339933;">&gt;</span>
        <span style="color: #339933;">&lt;</span>a href<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;/?controller=Feed&amp;action=add&quot;</span> data<span style="color: #339933;">-</span>role<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;button&quot;</span> data<span style="color: #339933;">-</span>icon<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;plus&quot;</span><span style="color: #339933;">&gt;</span><span style="color: #000000; font-weight: bold;">&lt;?</span>php <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">languages</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'add'</span><span style="color: #009900;">&#93;</span><span style="color: #000000; font-weight: bold;">?&gt;</span><span style="color: #339933;">&lt;/</span>a<span style="color: #339933;">&gt;</span>
    <span style="color: #339933;">&lt;/</span>div<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;/</span>div<span style="color: #339933;">&gt;</span></pre></td></tr></table></div>

<p>Lets write the index specific view, this view will list the feeds. open a new file under business/front/views/Feed/index.php and add the following lines :</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p73code36'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p7336"><td class="code" id="p73code36"><pre class="php" style="font-family:monospace;">        <span style="color: #339933;">&lt;</span>ul data<span style="color: #339933;">-</span>role<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;listview&quot;</span> data<span style="color: #339933;">-</span>inset<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;true&quot;</span> data<span style="color: #339933;">-</span>theme<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;c&quot;</span> data<span style="color: #339933;">-</span>dividertheme<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;b&quot;</span><span style="color: #339933;">&gt;</span>
        <span style="color: #339933;">&lt;</span>li data<span style="color: #339933;">-</span>role<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;list-divider&quot;</span><span style="color: #339933;">&gt;</span><span style="color: #000000; font-weight: bold;">&lt;?</span>php <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">languages</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'list'</span><span style="color: #009900;">&#93;</span><span style="color: #000000; font-weight: bold;">?&gt;</span><span style="color: #339933;">&lt;/</span>li<span style="color: #339933;">&gt;</span>
        <span style="color: #000000; font-weight: bold;">&lt;?php</span>
        <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">count</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">feeds</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
        <span style="color: #009900;">&#123;</span>
            <span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">feeds</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$feed</span><span style="color: #009900;">&#41;</span>
            <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">?&gt;</span>
            <span style="color: #339933;">&lt;</span>li<span style="color: #339933;">&gt;&lt;</span>a href<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;/?controller=Feed&amp;action=detail&amp;id=&lt;?php echo <span style="color: #006699; font-weight: bold;">$feed-&gt;id</span>?&gt;&quot;</span><span style="color: #339933;">&gt;</span><span style="color: #000000; font-weight: bold;">&lt;?</span>php <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$feed</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">name</span><span style="color: #339933;">;</span><span style="color: #000000; font-weight: bold;">?&gt;</span><span style="color: #339933;">&lt;/</span>a<span style="color: #339933;">&gt;&lt;/</span>li<span style="color: #339933;">&gt;</span>
        <span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #009900;">&#125;</span>
        <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
&nbsp;
        <span style="color: #339933;">&lt;</span>li<span style="color: #339933;">&gt;</span><span style="color: #000000; font-weight: bold;">&lt;?</span>php <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">languages</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'no_feeds'</span><span style="color: #009900;">&#93;</span><span style="color: #000000; font-weight: bold;">?&gt;</span><span style="color: #339933;">&lt;/</span>li<span style="color: #339933;">&gt;</span>
        <span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #009900;">&#125;</span><span style="color: #000000; font-weight: bold;">?&gt;</span>
        <span style="color: #339933;">&lt;/</span>ul<span style="color: #339933;">&gt;</span></pre></td></tr></table></div>

<p>In the index.php, all we do is that we are looping through the feed items to display the name and add a link to the detail page.<br />
With those files, the view part is almost complete. We should move forward to add the language variables. This will be explained in the next section <a href="http://simplemvc.berejeb.com/2010/11/the-business-configuration-files/">The configuration and helpers</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://simplemvc.berejeb.com/2010/11/a-first-view/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>A first model definition</title>
		<link>http://simplemvc.berejeb.com/2010/11/a-first-model-definition/</link>
		<comments>http://simplemvc.berejeb.com/2010/11/a-first-model-definition/#comments</comments>
		<pubDate>Sat, 27 Nov 2010 20:47:29 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Cookbook]]></category>

		<guid isPermaLink="false">http://simplemvc.berejeb.com/?p=71</guid>
		<description><![CDATA[In the previous section, we wrote our indexAction which makes use of a FeedModel model. Like the controllers, the models are modelized by classes. Again, you can choose the filename [...]]]></description>
			<content:encoded><![CDATA[<p>In the previous section, we wrote our indexAction which makes use of a FeedModel model. Like the controllers, the models are modelized by classes. Again, you can choose the filename you want to store the models, Simple MVC will find the model by itself. Despite, we follow a folder hierarchy and some standards to place each file in an appropriate folder. The models are places under business/{your-module-application}/models. So in our case business/front/models.<br />
So lets create our FeedModel under that folder:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p71code39'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p7139"><td class="code" id="p71code39"><pre class="php" style="font-family:monospace;"><span style="color: #009933; font-style: italic;">/**
 * Feed Model
 */</span>
<span style="color: #000000; font-weight: bold;">class</span> FeedModel <span style="color: #000000; font-weight: bold;">extends</span> CoreModel
<span style="color: #009900;">&#123;</span>
    <span style="color: #009933; font-style: italic;">/**
     * Table Name
     *
     * @var mixed  Defaults to 'feed'.
     */</span>
    <span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000088;">$_tableName</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'feed'</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #009933; font-style: italic;">/**
     * Table keys
     *
     * @var array  Defaults to array('id').
     */</span>
    <span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000088;">$_tableKeys</span> <span style="color: #339933;">=</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: #339933;">;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">// public properties</span>
    <span style="color: #009933; font-style: italic;">/**
     * Feed Name
     *
     * @var string  Defaults to null.
     */</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000088;">$name</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">null</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #009933; font-style: italic;">/**
     * Feed Url
     *
     * @var string  Defaults to null.
     */</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000088;">$url</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">null</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #009933; font-style: italic;">/**
     * Items to be shown
     *
     * @var int  Defaults to null.
     */</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000088;">$itemsNumber</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">null</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>As you notice, the two protected properties of the Feed model will specify the table name and the table keys. the following will specify the properties, (the fields in the table). At the current version, Simple MVC is still implementing the Active Record pattern, However, this is subject to change in latter version to implement another pattern which will allow to have some separation of the table definition from the model itself, and to allow dis-coupling column names with properties names.<br />
You understand though that we need to have to create a table corresponding to the model. Here is the SQL :</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p71code40'); return false;">View Code</a> SQL</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p7140"><td class="code" id="p71code40"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">TABLE</span> <span style="color: #993333; font-weight: bold;">IF</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">EXISTS</span> <span style="color: #ff0000;">`feed`</span> <span style="color: #66cc66;">&#40;</span>
  <span style="color: #ff0000;">`id`</span> int<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">11</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span> <span style="color: #993333; font-weight: bold;">AUTO_INCREMENT</span><span style="color: #66cc66;">,</span>
  <span style="color: #ff0000;">`name`</span> varchar<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">255</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
  <span style="color: #ff0000;">`url`</span> varchar<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">255</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
  <span style="color: #ff0000;">`itemsNumber`</span> int<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">11</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
  <span style="color: #993333; font-weight: bold;">PRIMARY</span> <span style="color: #993333; font-weight: bold;">KEY</span> <span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">`id`</span><span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#41;</span> ENGINE<span style="color: #66cc66;">=</span>MyISAM  <span style="color: #993333; font-weight: bold;">DEFAULT</span> CHARSET<span style="color: #66cc66;">=</span>utf8 ;
&nbsp;
<span style="color: #66cc66;">//</span> make some <span style="color: #993333; font-weight: bold;">insert</span> directly when you <span style="color: #993333; font-weight: bold;">create</span> your <span style="color: #993333; font-weight: bold;">tables</span>
<span style="color: #993333; font-weight: bold;">INSERT</span> <span style="color: #993333; font-weight: bold;">INTO</span> <span style="color: #ff0000;">`feed`</span> <span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">`id`</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">`name`</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">`url`</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">`itemsNumber`</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">VALUES</span>
<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'Anis berejeb'</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'http://feeds.feedburner.com/AnisBerejeb'</span><span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">5</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span>
<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">2</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'Houssem Bensalem'</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'http://www.hbensalem.com/feed/'</span><span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">4</span><span style="color: #66cc66;">&#41;</span>;</pre></td></tr></table></div>

<p>This is all we need for the model, all the magic is here since the FeedModel extends the CoreModel. However, the FeedModel is the placeholder where you will do your Data related logic. For example if you need to write some specific methods to deal with the data and return a certain collection or a certain instance, it should be in the model and not in the controller. The controller has just to &#8220;ask&#8221; the model to give him the data needed.<br />
So Let&#8217;s continue to have our working index page, let&#8217;s have a look at <a href="http://simplemvc.berejeb.com/2010/11/a-first-view/">the view section</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://simplemvc.berejeb.com/2010/11/a-first-model-definition/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>A first controller action</title>
		<link>http://simplemvc.berejeb.com/2010/11/a-first-controller-action/</link>
		<comments>http://simplemvc.berejeb.com/2010/11/a-first-controller-action/#comments</comments>
		<pubDate>Sat, 27 Nov 2010 20:46:42 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Cookbook]]></category>

		<guid isPermaLink="false">http://simplemvc.berejeb.com/?p=69</guid>
		<description><![CDATA[The controller is modelized by a class that should be placed under business/{your-module}/controllers/. So in our case : business/front/controllers/. Just for a purpose of file lisibility, you can name your [...]]]></description>
			<content:encoded><![CDATA[<p>The controller is modelized by a class that should be placed under business/{your-module}/controllers/. So in our case  : business/front/controllers/. Just for a purpose of file lisibility, you can name your file Controller.php, you can name your file whatever you want, Simple MVC will find it <img src='http://simplemvc.berejeb.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> . We will create a FeedController that will handle the logic of<br />
- adding feeds<br />
- calling the feed urls and getting the feed items<br />
- displaying the feed detail<br />
So if we analyse those few lines, we will notice that we need some methods in our controller to :<br />
- show the list page : this will be  our index page, we will call it indexAction<br />
- show the detail page : this will be our detail page, we will call it detailAction<br />
- show an add page : we need an addAction<br />
- save the added feed : we need a saveAction.<br />
we will need to have few other method to do some glue.<br />
So lets start!</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p69code44'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p6944"><td class="code" id="p69code44"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">class</span>  FeedController <span style="color: #000000; font-weight: bold;">extends</span> CoreController
<span style="color: #009900;">&#123;</span>
    <span style="color: #009933; font-style: italic;">/**
     * Inject dependencies
     *
     * @param  Container  $container The Container
     */</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> setContainer<span style="color: #009900;">&#40;</span>Container <span style="color: #000088;">$container</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        parent<span style="color: #339933;">::</span><span style="color: #004000;">setContainer</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$container</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #666666; font-style: italic;">// database is set on the business layer. this will allow the use of</span>
        <span style="color: #666666; font-style: italic;">// the mvc without coupling automatically the database.</span>
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Database</span>           <span style="color: #339933;">=</span> <span style="color: #000088;">$container</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'Database'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Request</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$container</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'Request'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">languages</span>   <span style="color: #339933;">=</span>  <span style="color: #000088;">$container</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'Language'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>The first method we wrote is setContainer. this method allows us to customize what we need to have as accessible objects in our controller, it takes an instance of a Container, and gets some objects. In this case, we collect the Database object, since we need to store the feed addresses, the Request object since we need to deal with request variables, and the languages array since we need to manage many languages in our application.<br />
Lets continue, the second method we will write is the alwaysAction, this action is actually always called before triggering our actions. Remember the call of frontDispatcher->route in the bootstrap file,  this method will actually call the alwaysAction before calling our specific one (indexAction, addAction etc.). But why we need to write an always Action for our case? the response is that in all our actions, we will need to have an instance of the model we will use. for example, to list the feeds, we need this instance, to show the details, we will need it also etc. So instead of having to instanciate it in every action, we will override the alwaysAction and have our model instance in  ther. the method will look like :</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p69code45'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p6945"><td class="code" id="p69code45"><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> alwaysAction<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        parent<span style="color: #339933;">::</span><span style="color: #004000;">alwaysAction</span><span style="color: #009900;">&#40;</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;">model</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> FeedModel<span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Database</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>As you noticed, the model instance is also a class, and takes a database instance as a constructor parameter. We will look more in detail at the model in the following actions, and in the <a href="#link-to-model-section">Understanding the Models</a> section.<br />
Next! we will write our index action, here is the code:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p69code46'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p6946"><td class="code" id="p69code46"><pre class="php" style="font-family:monospace;">    <span style="color: #009933; font-style: italic;">/**
     * Index Action
     * will list the feeds
     */</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> indexAction<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$feeds</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">model</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">findAll</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #009900; font-weight: bold;">false</span> <span style="color: #339933;">!==</span> <span style="color: #000088;">$feeds</span><span style="color: #009900;">&#41;</span>
        <span style="color: #009900;">&#123;</span>
            <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">view</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">feeds</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$feeds</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">fetchAll</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></td></tr></table></div>

<p>That&#8217;s it? yes, this is all we need to have for the moment <img src='http://simplemvc.berejeb.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' />  what we are doing here is that: we get all our feed using the findAll method of the model, and fetch all of them in the view. We didn&#8217;t spoke about the feed yet, we will do that later on. all you need to understand now is that we are passing the feeds to the view, it is its responsibility to display them.<br />
We need to make that first page work, what we are missing to get this working? the model definition, and the view definition. so lets see how to <a href="http://simplemvc.berejeb.com/2010/11/a-first-model-definition/">add our model definition</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://simplemvc.berejeb.com/2010/11/a-first-controller-action/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>The bootstrap file</title>
		<link>http://simplemvc.berejeb.com/2010/11/the-bootstrap-file/</link>
		<comments>http://simplemvc.berejeb.com/2010/11/the-bootstrap-file/#comments</comments>
		<pubDate>Sat, 27 Nov 2010 20:45:14 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Cookbook]]></category>

		<guid isPermaLink="false">http://simplemvc.berejeb.com/?p=67</guid>
		<description><![CDATA[the mean of www directory is to handle your webroot files. this is the only folder that should be accessible via your web server, also, you can have many webroots [...]]]></description>
			<content:encoded><![CDATA[<p>the  mean of www directory is to handle your webroot files. this is the only folder that should be accessible via your web server, also, you can have many webroots that are binded to each of your applications. in this way you share the api and the business code between your applications.<br />
First, create an index.php file and edit it. The first thing we have to do is to import the libraries we need to load: here is the code</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p67code49'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p6749"><td class="code" id="p67code49"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// include the configuration file</span>
<span style="color: #b1b100;">require_once</span><span style="color: #009900;">&#40;</span><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> <span style="color: #0000ff;">'/../conf/configuration_front.php'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">// include the autoload manager</span>
<span style="color: #b1b100;">require_once</span><span style="color: #009900;">&#40;</span><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> <span style="color: #0000ff;">'/../core/autoloadManager.php'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">// set the cache file for the autoload</span>
autoloadManager<span style="color: #339933;">::</span><span style="color: #004000;">setSaveFile</span><span style="color: #009900;">&#40;</span><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> <span style="color: #0000ff;">'/../tmp/front.php'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">// add the folders you want to the  autoload, you should add always CORE to have the core files</span>
autoloadManager<span style="color: #339933;">::</span><span style="color: #004000;">addFolder</span><span style="color: #009900;">&#40;</span>CORE<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
autoloadManager<span style="color: #339933;">::</span><span style="color: #004000;">addFolder</span><span style="color: #009900;">&#40;</span>BUSINESS<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">// trigger the autoload registration</span>
<span style="color: #990000;">spl_autoload_register</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'autoloadManager::loadClass'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>Second, we will write some logic to handle the public or protected sections of our websites, inject our needed dependencies to the dispatcher and trigger the routing method to call the appropriate method in the controller. Here is the code :</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p67code50'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p6750"><td class="code" id="p67code50"><pre class="php" style="font-family:monospace;">try
<span style="color: #009900;">&#123;</span>
    <span style="color: #666666; font-style: italic;">// get the dispatcher instance</span>
    <span style="color: #000088;">$front</span> <span style="color: #339933;">=</span> frontDispatcher<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>
    <span style="color: #666666; font-style: italic;">// get the actions</span>
    <span style="color: #000088;">$actions</span> <span style="color: #339933;">=</span> AccessHelper<span style="color: #339933;">::</span><span style="color: #004000;">getActions</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;">// authenticate using the actions configuration</span>
    <span style="color: #000088;">$AuthManager</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> AuthManager<span style="color: #009900;">&#40;</span><span style="color: #000088;">$actions</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #666666; font-style: italic;">// tell the Auth Manager where to route if the authentication failed</span>
    <span style="color: #000088;">$AuthManager</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">authenticate</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$front</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'/?controller=Feed&amp;amp;action=index'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #666666; font-style: italic;">// get the appropriate application controller</span>
    <span style="color: #000088;">$Container</span> <span style="color: #339933;">=</span> ContainerFactory<span style="color: #339933;">::</span><span style="color: #004000;">get</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'front'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #666666; font-style: italic;">// inject the access configuration</span>
    <span style="color: #000088;">$Container</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'Access'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$actions</span><span style="color: #339933;">;</span>
    <span style="color: #666666; font-style: italic;">// inject the Authentication object</span>
    <span style="color: #000088;">$Container</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'AuthManager'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$AuthManager</span><span style="color: #339933;">;</span>
    <span style="color: #666666; font-style: italic;">// inject the request object</span>
    <span style="color: #000088;">$Container</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'Request'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_REQUEST</span><span style="color: #339933;">;</span>
    <span style="color: #666666; font-style: italic;">// inject the session object</span>
    <span style="color: #000088;">$Container</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'Session'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> SessionManager<span style="color: #339933;">::</span><span style="color: #004000;">getSession</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'front'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">// Route using the container as a confi</span>
    <span style="color: #000088;">$front</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">route</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$Container</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
catch <span style="color: #009900;">&#40;</span>Exception <span style="color: #000088;">$e</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
        <span style="color: #666666; font-style: italic;">// instanciate the debugging console, true is for debugging mode, false is the default</span>
        <span style="color: #000088;">$console</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> DebugConsole<span style="color: #009900;">&#40;</span><span style="color: #000088;">$e</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #666666; font-style: italic;">// render the errors</span>
        <span style="color: #000088;">$console</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">render</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Ok, I think this bunch of code needs some explanation.  You may notice that there is maybe a lot of code for a bootstrapper, you could be right. However, I prefer to see what the framework is supposed to do for those action instead of having them at a separate layer. So lets explain the code :</p>
<ul>
<li><em>$front = frontDispatcher::getInstance(); </em>: This is quite simple, we are getting the instance of the front dispatcher.</li>
</ul>
<p>next &#8211; and if we need  to use the <a href="#link-to-access-manager">Authentication and access manager</a> , we need to add the following lines. Basically, the AccessHelper::getActions will return the list of the public and protected actions of our applications. The helper is related to a configuration file in which you can customize if the user should be authentified or not to access a certain action. The authenticate method of the AuthManager takes as parameters the dispatcher and the default url if the authentication fails.</p>
<ul>
<li>$actions = AccessHelper::getActions();</li>
<li>$AuthManager = new AuthManager($actions);</li>
<li>$AuthManager->authenticate($front, &#8216;/?controller=Feed&amp;amp;action=index&#8217;);</li>
</ul>
<p>The folloging lines the code contains concern the Dependency injection container. The idea is that we have to pass all the dependencies of our controller from outside. The mechanism is more explained in the section   <a href="#link-to-dependency-action-container">Dependency injection container</a> of this tutorial. </p>
<ul>
<li>
             // get the appropriate application controller<br />
    $Container = ContainerFactory::get(&#8216;front&#8217;);<br />
    // inject the access configuration<br />
    $Container['Access'] = $actions;<br />
    // inject the Authentication object<br />
    $Container['AuthManager'] = $AuthManager;<br />
    // inject the request object<br />
    $Container['Request'] = $_REQUEST;<br />
    // inject the session object<br />
    $Container['Session'] = SessionManager::getSession(&#8216;front&#8217;);
    </li>
</ul>
<p>The last line of the try block will trigger the route method of the dispatcher. this allows to call the approppriate action on the approppriate controller.<br />
In the catch block, using the DebugConsole, we display a friendly message to the user. A second parameter, set to true in a debug mode,  allows displaying the exception stack trace for the developer.</p>
<p>So at this moment, the frontDispatcher root method is called, we have now to start <a href="http://simplemvc.berejeb.com/2010/11/a-first-controller-action/">writing our first controller!</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://simplemvc.berejeb.com/2010/11/the-bootstrap-file/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

