<?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>Inside DealTaker &#187; technology</title>
	<atom:link href="http://www.dealtaker.com/blog/category/technology/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.dealtaker.com/blog</link>
	<description>All Things Deal Oriented</description>
	<lastBuildDate>Sat, 20 Mar 2010 01:41:30 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Kohana PHP 3.0 (KO3) Tutorial Part 6</title>
		<link>http://www.dealtaker.com/blog/2010/03/03/kohana-php-3-0-ko3-tutorial-part-6/</link>
		<comments>http://www.dealtaker.com/blog/2010/03/03/kohana-php-3-0-ko3-tutorial-part-6/#comments</comments>
		<pubDate>Wed, 03 Mar 2010 22:02:12 +0000</pubDate>
		<dc:creator>ellisgl</dc:creator>
				<category><![CDATA[technology]]></category>
		<category><![CDATA[framework]]></category>
		<category><![CDATA[KO3]]></category>
		<category><![CDATA[kohana]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[routes]]></category>
		<category><![CDATA[routing]]></category>

		<guid isPermaLink="false">http://www.dealtaker.com/blog/?p=2037</guid>
		<description><![CDATA[Welcome to the sixth part in this series on how to develop with Kohana PHP V3 (KO3). If you haven&#8217;t read any of previous parts yet, I would click here and read them before going on. In this tutorial we will be going over Routes and Routing.

What is Routing? Well Routing is nothing more than [...]]]></description>
			<content:encoded><![CDATA[<p>Welcome to the sixth part in this series on how to develop with Kohana PHP V3 (KO3). If you haven&#8217;t read any of previous parts yet, <a href="../tag/ko3/">I would click here and read them before going on</a>. In this tutorial we will be going over Routes and Routing.<br />
<span id="more-2037"></span><br />
What is Routing? Well Routing is nothing more than taking a request, looking at it and directing it to the right place. Think of it Kohana&#8217;s version of the .htaccess file. So why would you want to use routing you might ask. Well there are so many reasons why you would want to use routing, so I&#8217;m not going to over all of them, but give you a couple examples of how to setup routes for different scenarios.</p>
<p>So what does a route look like? Open up &#8220;bootstrap.php&#8221; located in &#8220;application/&#8221;, and scroll down to the comment that says:</p>
<pre>/**
 * Set the routes. Each route must have a minimum of a name, a URI and a set of
 * defaults for the URI.
 */</pre>
<p>The next thing you should see is something like this:</p>
<pre>Route::set('default', '(&lt;controller&gt;(/&lt;action&gt;(/&lt;id&gt;)))')
     -&gt;defaults(array('controller' =&gt; 'welcome',
                      'action'     =&gt; 'index'));</pre>
<p>So we have a route setup initially for us, but what does this tell us. If we break it down we get:<br />
1. Set a route with the name &#8220;default&#8221;<br />
2. &#8216;(&lt;controller&gt;(/&lt;action&gt;(/&lt;id&gt;)))&#8217;  Tells the route the controller, action and id are optional. The parentheses are containers that denote if an option is opional or not and the less / greater than symbols tell the the router to assign the value to the variable of the value in-between the less / greater than symbols.<br />
3. The default values for the controller is &#8220;welcome&#8221; and the default value for the action is &#8220;index&#8221;</p>
<p>So when we go to &#8220;http://yourserver/mykohana3/&#8221;, the router see that we have not set a controller nor an action in our URL. It will go through the route rules that we have set to find a match. In our case, we have a default route, which is named &#8220;default&#8221;. This default route will replace the missing controller with &#8220;welcome&#8221; and the action with &#8220;index&#8221; and the rest of the system will process it. Simple so far?</p>
<p>If we were to to &#8220;http://yourserver/mykohana3/hmvc/&#8221;, the router would notice that the controller has been set, but not the action. The router then assign the default action value of &#8220;index&#8221; for us.</p>
<p>You might have noticed the optional &#8220;id&#8221; in the route. This I would say is pretty commonly used and we could pass an ID on to our action. Example:<br />
&#8220;http://yourserver/mykohana3/hmvc/index/111&#8243;. Of course this example will not do anything special since we didn&#8217;t set up any logic to handle it. Now what if we browsed to &#8220;http://yourserver/mykohana3/hmvc/index/111/222&#8243;? We get an error. This is because our router rule is strict and says we can only route for upwards of 3 segments (action/controller/id) and the /222 creates a fourth. To over come this we can though in a overflow handler rule into our default route.</p>
<pre>Route::set('default', '(&lt;controller&gt;(/&lt;action&gt;(/&lt;id&gt;(/&lt;overflow&gt;))))', array('overflow' =&gt; '.*?'))
     -&gt;defaults(array('controller' =&gt; 'welcome',
                      'action'     =&gt; 'index'));</pre>
<p>If you save the &#8216;bootstrap.php&#8217; file and reload, you should not see an error now.</p>
<p>You might notice that we&#8217;ve added in an extra array &#8220;array(&#8217;overflow&#8217; =&gt; &#8216;.*?&#8217;)&#8221;. This basically sets up a REGEX rules for the &#8220;overflow&#8221; option which tell the router to capture everything, including slashes and pass it as our &#8220;overflow&#8221; argument. So if slashes are captured, the router will no longer try to split out the options on slashes.</p>
<p>Lets go back to this &#8220;id&#8221; option we see in our route. Well, anything we put in that area will be passed to our action. If our id&#8217;s are integers, we might want to error out if we pass a non integer. One way we can do this is with the route:</p>
<pre>Route::set('default', '(&lt;controller&gt;(/&lt;action&gt;(/&lt;id&gt;(/&lt;overflow&gt;))))', array('id' =&gt; '[[:digit:]]{1,}', 'overflow' =&gt; '.*?'))
     -&gt;defaults(array('controller' =&gt; 'welcome',
                      'action'     =&gt; 'index'));</pre>
<p>So now if you were go to: &#8220;http://yourserver/mykohana3/hmvc/index/xxx&#8221;, you would get an error about not being able to find the route, which should translate to a 404 in a production environment. Of course you could check the id for an integer inside the action action and decide how to handle it.</p>
<p>Now lets create a route that isn&#8217;t our default route. Add the following to the &#8220;bootstrap.php&#8221; before the default route:</p>
<pre>Route::set('monkeys', 'monkeys(/&lt;action&gt;(/&lt;id&gt;))')
     -&gt;defaults(array('controller' =&gt; 'ko3',
                      'action'     =&gt; 'posts'));</pre>
<p>Now if you were open up &#8220;http://yourserver/mykohana3/monkeys&#8221;, you would end up with the &#8220;posts&#8221; action of the &#8220;ko3&#8243; controller. If you notice, the &#8220;monkeys&#8221; in the controller spot is not enclosed by parentheses, meaning that is not optional. So the router see &#8220;monkeys&#8221; in the controller spot and triggers this rule set.</p>
<p>Here&#8217;s an example you might want to use to serve up some static pages (Totally stole this from the <a href="http://kerkness.ca/wiki/doku.php?id=routing:routing_basics" target="_blank">Unofficial Kohana 3.0 Wiki</a>):</p>
<pre>Route::set('static', '&lt;page&gt;', array('page' =&gt; 'about|faq|locations'))
	   -&gt;defaults(array('controller' =&gt; 'page',
                      'action'     =&gt; 'static'));</pre>
<p>There is a bit more you could do with routes, but the above should cover the majority of things you would want to use route for.</p>
<p>Until next time when we will go over modules and helpers, happy coding.<br />
Sources used: <a href="http://kerkness.ca/wiki/doku.php" target="_blank">Unofficial Kohana 3 Wiki</a></p>

<div class="sociable">
<div class="sociable_tagline">
<strong>Share and Enjoy:</strong>
</div>
<ul>
	<li class="sociablefirst"><a rel="nofollow"  target="_blank" href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fwww.dealtaker.com%2Fblog%2F2010%2F03%2F03%2Fkohana-php-3-0-ko3-tutorial-part-6%2F&amp;title=Kohana%20PHP%203.0%20%28KO3%29%20Tutorial%20Part%206&amp;bodytext=Welcome%20to%20the%20sixth%20part%20in%20this%20series%20on%20how%20to%20develop%20with%20Kohana%20PHP%20V3%20%28KO3%29.%20If%20you%20haven%27t%20read%20any%20of%20previous%20parts%20yet%2C%20I%20would%20click%20here%20and%20read%20them%20before%20going%20on.%20In%20this%20tutorial%20we%20will%20be%20going%20over%20Routes%20and%20Routing.%0D%0A%0D%0AWhat%20i" title="Digg"><img src="http://www.dealtaker.com/blog/wp-content/plugins/sociable/images/digg.png" title="Digg" alt="Digg" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://delicious.com/post?url=http%3A%2F%2Fwww.dealtaker.com%2Fblog%2F2010%2F03%2F03%2Fkohana-php-3-0-ko3-tutorial-part-6%2F&amp;title=Kohana%20PHP%203.0%20%28KO3%29%20Tutorial%20Part%206&amp;notes=Welcome%20to%20the%20sixth%20part%20in%20this%20series%20on%20how%20to%20develop%20with%20Kohana%20PHP%20V3%20%28KO3%29.%20If%20you%20haven%27t%20read%20any%20of%20previous%20parts%20yet%2C%20I%20would%20click%20here%20and%20read%20them%20before%20going%20on.%20In%20this%20tutorial%20we%20will%20be%20going%20over%20Routes%20and%20Routing.%0D%0A%0D%0AWhat%20i" title="del.icio.us"><img src="http://www.dealtaker.com/blog/wp-content/plugins/sociable/images/delicious.png" title="del.icio.us" alt="del.icio.us" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://www.facebook.com/share.php?u=http%3A%2F%2Fwww.dealtaker.com%2Fblog%2F2010%2F03%2F03%2Fkohana-php-3-0-ko3-tutorial-part-6%2F&amp;t=Kohana%20PHP%203.0%20%28KO3%29%20Tutorial%20Part%206" title="Facebook"><img src="http://www.dealtaker.com/blog/wp-content/plugins/sociable/images/facebook.png" title="Facebook" alt="Facebook" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://twitter.com/home?status=Kohana%20PHP%203.0%20%28KO3%29%20Tutorial%20Part%206%20-%20http%3A%2F%2Fwww.dealtaker.com%2Fblog%2F2010%2F03%2F03%2Fkohana-php-3-0-ko3-tutorial-part-6%2F" title="Twitter"><img src="http://www.dealtaker.com/blog/wp-content/plugins/sociable/images/twitter.png" title="Twitter" alt="Twitter" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fwww.dealtaker.com%2Fblog%2F2010%2F03%2F03%2Fkohana-php-3-0-ko3-tutorial-part-6%2F&amp;title=Kohana%20PHP%203.0%20%28KO3%29%20Tutorial%20Part%206" title="StumbleUpon"><img src="http://www.dealtaker.com/blog/wp-content/plugins/sociable/images/stumbleupon.png" title="StumbleUpon" alt="StumbleUpon" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://www.mixx.com/submit?page_url=http%3A%2F%2Fwww.dealtaker.com%2Fblog%2F2010%2F03%2F03%2Fkohana-php-3-0-ko3-tutorial-part-6%2F&amp;title=Kohana%20PHP%203.0%20%28KO3%29%20Tutorial%20Part%206" title="Mixx"><img src="http://www.dealtaker.com/blog/wp-content/plugins/sociable/images/mixx.png" title="Mixx" alt="Mixx" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://www.google.com/bookmarks/mark?op=edit&amp;bkmk=http%3A%2F%2Fwww.dealtaker.com%2Fblog%2F2010%2F03%2F03%2Fkohana-php-3-0-ko3-tutorial-part-6%2F&amp;title=Kohana%20PHP%203.0%20%28KO3%29%20Tutorial%20Part%206&amp;annotation=Welcome%20to%20the%20sixth%20part%20in%20this%20series%20on%20how%20to%20develop%20with%20Kohana%20PHP%20V3%20%28KO3%29.%20If%20you%20haven%27t%20read%20any%20of%20previous%20parts%20yet%2C%20I%20would%20click%20here%20and%20read%20them%20before%20going%20on.%20In%20this%20tutorial%20we%20will%20be%20going%20over%20Routes%20and%20Routing.%0D%0A%0D%0AWhat%20i" title="Google Bookmarks"><img src="http://www.dealtaker.com/blog/wp-content/plugins/sociable/images/googlebookmark.png" title="Google Bookmarks" alt="Google Bookmarks" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://reddit.com/submit?url=http%3A%2F%2Fwww.dealtaker.com%2Fblog%2F2010%2F03%2F03%2Fkohana-php-3-0-ko3-tutorial-part-6%2F&amp;title=Kohana%20PHP%203.0%20%28KO3%29%20Tutorial%20Part%206" title="Reddit"><img src="http://www.dealtaker.com/blog/wp-content/plugins/sociable/images/reddit.png" title="Reddit" alt="Reddit" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://technorati.com/faves?add=http%3A%2F%2Fwww.dealtaker.com%2Fblog%2F2010%2F03%2F03%2Fkohana-php-3-0-ko3-tutorial-part-6%2F" title="Technorati"><img src="http://www.dealtaker.com/blog/wp-content/plugins/sociable/images/technorati.png" title="Technorati" alt="Technorati" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://buzz.yahoo.com/submit/?submitUrl=http%3A%2F%2Fwww.dealtaker.com%2Fblog%2F2010%2F03%2F03%2Fkohana-php-3-0-ko3-tutorial-part-6%2F&amp;submitHeadline=Kohana%20PHP%203.0%20%28KO3%29%20Tutorial%20Part%206&amp;submitSummary=Welcome%20to%20the%20sixth%20part%20in%20this%20series%20on%20how%20to%20develop%20with%20Kohana%20PHP%20V3%20%28KO3%29.%20If%20you%20haven%27t%20read%20any%20of%20previous%20parts%20yet%2C%20I%20would%20click%20here%20and%20read%20them%20before%20going%20on.%20In%20this%20tutorial%20we%20will%20be%20going%20over%20Routes%20and%20Routing.%0D%0A%0D%0AWhat%20i&amp;submitCategory=science&amp;submitAssetType=text" title="Yahoo! Buzz"><img src="http://www.dealtaker.com/blog/wp-content/plugins/sociable/images/yahoobuzz.png" title="Yahoo! Buzz" alt="Yahoo! Buzz" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://www.myspace.com/Modules/PostTo/Pages/?u=http%3A%2F%2Fwww.dealtaker.com%2Fblog%2F2010%2F03%2F03%2Fkohana-php-3-0-ko3-tutorial-part-6%2F&amp;t=Kohana%20PHP%203.0%20%28KO3%29%20Tutorial%20Part%206" title="MySpace"><img src="http://www.dealtaker.com/blog/wp-content/plugins/sociable/images/myspace.png" title="MySpace" alt="MySpace" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://www.linkedin.com/shareArticle?mini=true&amp;url=http%3A%2F%2Fwww.dealtaker.com%2Fblog%2F2010%2F03%2F03%2Fkohana-php-3-0-ko3-tutorial-part-6%2F&amp;title=Kohana%20PHP%203.0%20%28KO3%29%20Tutorial%20Part%206&amp;source=Inside+DealTaker+All+Things+Deal+Oriented&amp;summary=Welcome%20to%20the%20sixth%20part%20in%20this%20series%20on%20how%20to%20develop%20with%20Kohana%20PHP%20V3%20%28KO3%29.%20If%20you%20haven%27t%20read%20any%20of%20previous%20parts%20yet%2C%20I%20would%20click%20here%20and%20read%20them%20before%20going%20on.%20In%20this%20tutorial%20we%20will%20be%20going%20over%20Routes%20and%20Routing.%0D%0A%0D%0AWhat%20i" title="LinkedIn"><img src="http://www.dealtaker.com/blog/wp-content/plugins/sociable/images/linkedin.png" title="LinkedIn" alt="LinkedIn" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="https://favorites.live.com/quickadd.aspx?marklet=1&amp;url=http%3A%2F%2Fwww.dealtaker.com%2Fblog%2F2010%2F03%2F03%2Fkohana-php-3-0-ko3-tutorial-part-6%2F&amp;title=Kohana%20PHP%203.0%20%28KO3%29%20Tutorial%20Part%206" title="Live"><img src="http://www.dealtaker.com/blog/wp-content/plugins/sociable/images/live.png" title="Live" alt="Live" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="mailto:?subject=Kohana%20PHP%203.0%20%28KO3%29%20Tutorial%20Part%206&amp;body=http%3A%2F%2Fwww.dealtaker.com%2Fblog%2F2010%2F03%2F03%2Fkohana-php-3-0-ko3-tutorial-part-6%2F" title="email"><img src="http://www.dealtaker.com/blog/wp-content/plugins/sociable/images/email_link.png" title="email" alt="email" class="sociable-hovers" /></a></li>
	<li class="sociablelast"><a rel="nofollow"  target="_blank" href="http://www.printfriendly.com/print?url=http%3A%2F%2Fwww.dealtaker.com%2Fblog%2F2010%2F03%2F03%2Fkohana-php-3-0-ko3-tutorial-part-6%2F&amp;partner=sociable" title="Print"><img src="http://www.dealtaker.com/blog/wp-content/plugins/sociable/images/printfriendly.png" title="Print" alt="Print" class="sociable-hovers" /></a></li>
</ul>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.dealtaker.com/blog/2010/03/03/kohana-php-3-0-ko3-tutorial-part-6/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>Kohana PHP 3.0 (KO3) Tutorial Part 5</title>
		<link>http://www.dealtaker.com/blog/2010/02/25/kohana-php-3-0-ko3-tutorial-part-5/</link>
		<comments>http://www.dealtaker.com/blog/2010/02/25/kohana-php-3-0-ko3-tutorial-part-5/#comments</comments>
		<pubDate>Thu, 25 Feb 2010 22:44:23 +0000</pubDate>
		<dc:creator>ellisgl</dc:creator>
				<category><![CDATA[technology]]></category>
		<category><![CDATA[framework]]></category>
		<category><![CDATA[HMVC]]></category>
		<category><![CDATA[KO3]]></category>
		<category><![CDATA[kohana]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://www.dealtaker.com/blog/?p=1991</guid>
		<description><![CDATA[Welcome to the fifth part in this series on how to develop with Kohana PHP V3 (KO3). If you haven&#8217;t read any of previous parts yet, I would click here and read them before going on. In this tutorial we will be going over the &#8220;H&#8221; in HMVC.

So most of you know what MVC is, [...]]]></description>
			<content:encoded><![CDATA[<p>Welcome to the fifth part in this series on how to develop with Kohana PHP V3 (KO3). If you haven&#8217;t read any of previous parts yet, <a href="../tag/ko3/">I would click here and read them before going on</a>. In this tutorial we will be going over the &#8220;H&#8221; in HMVC.<br />
<span id="more-1991"></span><br />
So most of you know what MVC is, but might not know about HMVC. HMVC extends MVC by allowing a controller to call on other controllers on do stuff, or doing stuff in an Hierarchical manor. Think modules that can work by themselves or in a groups. If that didn&#8217;t help, <a href="http://techportal.ibuildings.com/2010/02/22/scaling-web-applications-with-hmvc/">check out this article about the Hierarchical-Model-View-Controller pattern</a>.</p>
<p>So we&#8217;ve been design pages with a single controller as a page, with some actions that pulls data in from a model and populates a parts of a view to give us a complete browser page. Well, that can get messy with all the model calls and extra snippets we bring into with views. Using HMVC, we can organize our code a lot better, make more things reusable and with the way Kohana PHP 3 does HMVC, we can even make our application scale by calling out to other servers to give us our content for a section.</p>
<p>Lets go ahead and make a new controller:</p>
<pre>&lt;?php
defined('SYSPATH') or die('No direct script access.');

class Controller_Hmvc extends Controller_DefaultTemplate
 {
    public function action_index()
     {
        // Set meta data
        $this-&gt;template-&gt;title            = 'Kohana 3.0 HMVC Test';
        $this-&gt;template-&gt;meta_keywords    = 'PHP, Kohana, KO3, Framework, HMVC';
        $this-&gt;template-&gt;meta_description = 'A test of of the KO3 framework HMVC pattern';

        // Fill in content
        $ko3                              = array();
        $ko3['posts']                     = Request::factory('posts/getposts')-&gt;execute()-&gt;response;

        $this-&gt;template-&gt;content          = View::factory('pages/hmvc', $ko3);
     }

 }</pre>
<p>Save this as &#8220;hmvc.php&#8221; in &#8220;application/classes/controller&#8221;. The above should look pretty familiar. One line should stand out:</p>
<pre>$ko3['posts'] = Request::factory('posts/getposts')-&gt;execute()-&gt;response;</pre>
<p>This line is where the HMVC magic happen. This will call the controller &#8220;posts&#8221; an invoke the action &#8220;getposts&#8221;, execute the code and get the response. We take the response and save it to the array which we fill the view with.</p>
<p>Talking about views, let make our view for this controller:</p>
<pre>&lt;?php echo $posts;?&gt;</pre>
<p>Save this as &#8220;hmvc.php&#8221; in &#8220;application/views/pages/&#8221;</p>
<p>Now for the &#8220;posts&#8221; controller:</p>
<pre>&lt;?php
defined('SYSPATH') or die('No direct script access.');

class Controller_Posts extends Controller
 {
    public function action_index()
     {
     }

    public function action_getposts()
     {
        // Load model
        $posts           = new Model_Post();

        // Fill content array for view with last 10 posts.
        $content          = array();
        $content['posts'] = $posts-&gt;getLastTenPosts();

        // Render and output.
        $this-&gt;request-&gt;response   = View::factory('pages/hmvc_posts', $content);
     }
 }</pre>
<p>Save this as &#8220;posts.php&#8221; in &#8220;application/classes/controller&#8221;. Once again, pretty straight forward. This controller extends the basic controller, so nifty template or anything and is pretty much what we did in the last tutorial.</p>
<p>Now for the view.</p>
<pre>&lt;?php foreach($posts as $post):?&gt;
 &lt;h1&gt;&lt;?php echo $post['title'];?&gt;&lt;/h1&gt;
 &lt;?php echo $post['post'];?&gt;
 &lt;hr /&gt;
&lt;?php endforeach;?&gt;</pre>
<p>Save this as &#8220;hmvc_posts.php&#8221; under &#8220;applications/views/pages&#8221;.</p>
<p>Now if you point your browser to: &#8220;http://yourserver/mykohana3/hmvc&#8221;, you should see a couple posts up on the screen.</p>
<p>We can achieve the same result by calling the controller from the view instead of the controller. This is helpful for keeping it simple. So one template used all over the place, you wouldn&#8217;t have to worry about having to putting in all the HMVC stuff into the controllers that used that template.</p>
<p>Change the &#8220;hmvc&#8221; controller to look like this:</p>
<pre>&lt;?php
defined('SYSPATH') or die('No direct script access.');

class Controller_Hmvc extends Controller_DefaultTemplate
 {
    public function action_index()
     {
        // Set meta data
        $this-&gt;template-&gt;title            = 'Kohana 3.0 HMVC Test';
        $this-&gt;template-&gt;meta_keywords    = 'PHP, Kohana, KO3, Framework, HMVC';
        $this-&gt;template-&gt;meta_description = 'A test of of the KO3 framework HMVC pattern';

        // Fill in content
        $ko3                              = array();
        $ko3['content']                   = 'Hello there!';
         $this-&gt;template-&gt;content          = View::factory('pages/hmvc', $ko3);
     }
 }</pre>
<p>Now edit the &#8220;hmvc&#8221; view to look like this:</p>
<pre>&lt;?php echo $content;?&gt;&lt;br/&gt;
&lt;?php echo Request::factory('posts/getposts')-&gt;execute()-&gt;response;?&gt;</pre>
<p>This is example is pretty simple and we could expand this to use parameters to deliver the data in different ways, say, simple html, full html, xml, json, etc..</p>
<p>If you enjoyed this series of tutorials and want to throw me a bone, <a href="http://tk2.us/kmttax" target="_blank">click here to get your 10% off Turbo Tax coupon</a>!</p>
<p><a href="http://images.dealtaker.com/dealtaker/blog/ko3-tutorial/mykohana3_5.zip">Get the file for this tutorial here</a></p>
<p>Sources used: <a href="http://kerkness.ca/wiki/doku.php" target="_blank">Unofficial Kohana 3 Wiki</a>, <a href="http://techportal.ibuildings.com/2010/02/22/scaling-web-applications-with-hmvc/" target="_blank">iBuildings: Scaling Web Applications with HMVC</a></p>

<div class="sociable">
<div class="sociable_tagline">
<strong>Share and Enjoy:</strong>
</div>
<ul>
	<li class="sociablefirst"><a rel="nofollow"  target="_blank" href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fwww.dealtaker.com%2Fblog%2F2010%2F02%2F25%2Fkohana-php-3-0-ko3-tutorial-part-5%2F&amp;title=Kohana%20PHP%203.0%20%28KO3%29%20Tutorial%20Part%205&amp;bodytext=Welcome%20to%20the%20fifth%20part%20in%20this%20series%20on%20how%20to%20develop%20with%20Kohana%20PHP%20V3%20%28KO3%29.%20If%20you%20haven%27t%20read%20any%20of%20previous%20parts%20yet%2C%20I%20would%20click%20here%20and%20read%20them%20before%20going%20on.%20In%20this%20tutorial%20we%20will%20be%20going%20over%20the%20%22H%22%20in%20HMVC.%0D%0A%0D%0ASo%20most%20o" title="Digg"><img src="http://www.dealtaker.com/blog/wp-content/plugins/sociable/images/digg.png" title="Digg" alt="Digg" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://delicious.com/post?url=http%3A%2F%2Fwww.dealtaker.com%2Fblog%2F2010%2F02%2F25%2Fkohana-php-3-0-ko3-tutorial-part-5%2F&amp;title=Kohana%20PHP%203.0%20%28KO3%29%20Tutorial%20Part%205&amp;notes=Welcome%20to%20the%20fifth%20part%20in%20this%20series%20on%20how%20to%20develop%20with%20Kohana%20PHP%20V3%20%28KO3%29.%20If%20you%20haven%27t%20read%20any%20of%20previous%20parts%20yet%2C%20I%20would%20click%20here%20and%20read%20them%20before%20going%20on.%20In%20this%20tutorial%20we%20will%20be%20going%20over%20the%20%22H%22%20in%20HMVC.%0D%0A%0D%0ASo%20most%20o" title="del.icio.us"><img src="http://www.dealtaker.com/blog/wp-content/plugins/sociable/images/delicious.png" title="del.icio.us" alt="del.icio.us" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://www.facebook.com/share.php?u=http%3A%2F%2Fwww.dealtaker.com%2Fblog%2F2010%2F02%2F25%2Fkohana-php-3-0-ko3-tutorial-part-5%2F&amp;t=Kohana%20PHP%203.0%20%28KO3%29%20Tutorial%20Part%205" title="Facebook"><img src="http://www.dealtaker.com/blog/wp-content/plugins/sociable/images/facebook.png" title="Facebook" alt="Facebook" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://twitter.com/home?status=Kohana%20PHP%203.0%20%28KO3%29%20Tutorial%20Part%205%20-%20http%3A%2F%2Fwww.dealtaker.com%2Fblog%2F2010%2F02%2F25%2Fkohana-php-3-0-ko3-tutorial-part-5%2F" title="Twitter"><img src="http://www.dealtaker.com/blog/wp-content/plugins/sociable/images/twitter.png" title="Twitter" alt="Twitter" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fwww.dealtaker.com%2Fblog%2F2010%2F02%2F25%2Fkohana-php-3-0-ko3-tutorial-part-5%2F&amp;title=Kohana%20PHP%203.0%20%28KO3%29%20Tutorial%20Part%205" title="StumbleUpon"><img src="http://www.dealtaker.com/blog/wp-content/plugins/sociable/images/stumbleupon.png" title="StumbleUpon" alt="StumbleUpon" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://www.mixx.com/submit?page_url=http%3A%2F%2Fwww.dealtaker.com%2Fblog%2F2010%2F02%2F25%2Fkohana-php-3-0-ko3-tutorial-part-5%2F&amp;title=Kohana%20PHP%203.0%20%28KO3%29%20Tutorial%20Part%205" title="Mixx"><img src="http://www.dealtaker.com/blog/wp-content/plugins/sociable/images/mixx.png" title="Mixx" alt="Mixx" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://www.google.com/bookmarks/mark?op=edit&amp;bkmk=http%3A%2F%2Fwww.dealtaker.com%2Fblog%2F2010%2F02%2F25%2Fkohana-php-3-0-ko3-tutorial-part-5%2F&amp;title=Kohana%20PHP%203.0%20%28KO3%29%20Tutorial%20Part%205&amp;annotation=Welcome%20to%20the%20fifth%20part%20in%20this%20series%20on%20how%20to%20develop%20with%20Kohana%20PHP%20V3%20%28KO3%29.%20If%20you%20haven%27t%20read%20any%20of%20previous%20parts%20yet%2C%20I%20would%20click%20here%20and%20read%20them%20before%20going%20on.%20In%20this%20tutorial%20we%20will%20be%20going%20over%20the%20%22H%22%20in%20HMVC.%0D%0A%0D%0ASo%20most%20o" title="Google Bookmarks"><img src="http://www.dealtaker.com/blog/wp-content/plugins/sociable/images/googlebookmark.png" title="Google Bookmarks" alt="Google Bookmarks" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://reddit.com/submit?url=http%3A%2F%2Fwww.dealtaker.com%2Fblog%2F2010%2F02%2F25%2Fkohana-php-3-0-ko3-tutorial-part-5%2F&amp;title=Kohana%20PHP%203.0%20%28KO3%29%20Tutorial%20Part%205" title="Reddit"><img src="http://www.dealtaker.com/blog/wp-content/plugins/sociable/images/reddit.png" title="Reddit" alt="Reddit" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://technorati.com/faves?add=http%3A%2F%2Fwww.dealtaker.com%2Fblog%2F2010%2F02%2F25%2Fkohana-php-3-0-ko3-tutorial-part-5%2F" title="Technorati"><img src="http://www.dealtaker.com/blog/wp-content/plugins/sociable/images/technorati.png" title="Technorati" alt="Technorati" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://buzz.yahoo.com/submit/?submitUrl=http%3A%2F%2Fwww.dealtaker.com%2Fblog%2F2010%2F02%2F25%2Fkohana-php-3-0-ko3-tutorial-part-5%2F&amp;submitHeadline=Kohana%20PHP%203.0%20%28KO3%29%20Tutorial%20Part%205&amp;submitSummary=Welcome%20to%20the%20fifth%20part%20in%20this%20series%20on%20how%20to%20develop%20with%20Kohana%20PHP%20V3%20%28KO3%29.%20If%20you%20haven%27t%20read%20any%20of%20previous%20parts%20yet%2C%20I%20would%20click%20here%20and%20read%20them%20before%20going%20on.%20In%20this%20tutorial%20we%20will%20be%20going%20over%20the%20%22H%22%20in%20HMVC.%0D%0A%0D%0ASo%20most%20o&amp;submitCategory=science&amp;submitAssetType=text" title="Yahoo! Buzz"><img src="http://www.dealtaker.com/blog/wp-content/plugins/sociable/images/yahoobuzz.png" title="Yahoo! Buzz" alt="Yahoo! Buzz" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://www.myspace.com/Modules/PostTo/Pages/?u=http%3A%2F%2Fwww.dealtaker.com%2Fblog%2F2010%2F02%2F25%2Fkohana-php-3-0-ko3-tutorial-part-5%2F&amp;t=Kohana%20PHP%203.0%20%28KO3%29%20Tutorial%20Part%205" title="MySpace"><img src="http://www.dealtaker.com/blog/wp-content/plugins/sociable/images/myspace.png" title="MySpace" alt="MySpace" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://www.linkedin.com/shareArticle?mini=true&amp;url=http%3A%2F%2Fwww.dealtaker.com%2Fblog%2F2010%2F02%2F25%2Fkohana-php-3-0-ko3-tutorial-part-5%2F&amp;title=Kohana%20PHP%203.0%20%28KO3%29%20Tutorial%20Part%205&amp;source=Inside+DealTaker+All+Things+Deal+Oriented&amp;summary=Welcome%20to%20the%20fifth%20part%20in%20this%20series%20on%20how%20to%20develop%20with%20Kohana%20PHP%20V3%20%28KO3%29.%20If%20you%20haven%27t%20read%20any%20of%20previous%20parts%20yet%2C%20I%20would%20click%20here%20and%20read%20them%20before%20going%20on.%20In%20this%20tutorial%20we%20will%20be%20going%20over%20the%20%22H%22%20in%20HMVC.%0D%0A%0D%0ASo%20most%20o" title="LinkedIn"><img src="http://www.dealtaker.com/blog/wp-content/plugins/sociable/images/linkedin.png" title="LinkedIn" alt="LinkedIn" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="https://favorites.live.com/quickadd.aspx?marklet=1&amp;url=http%3A%2F%2Fwww.dealtaker.com%2Fblog%2F2010%2F02%2F25%2Fkohana-php-3-0-ko3-tutorial-part-5%2F&amp;title=Kohana%20PHP%203.0%20%28KO3%29%20Tutorial%20Part%205" title="Live"><img src="http://www.dealtaker.com/blog/wp-content/plugins/sociable/images/live.png" title="Live" alt="Live" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="mailto:?subject=Kohana%20PHP%203.0%20%28KO3%29%20Tutorial%20Part%205&amp;body=http%3A%2F%2Fwww.dealtaker.com%2Fblog%2F2010%2F02%2F25%2Fkohana-php-3-0-ko3-tutorial-part-5%2F" title="email"><img src="http://www.dealtaker.com/blog/wp-content/plugins/sociable/images/email_link.png" title="email" alt="email" class="sociable-hovers" /></a></li>
	<li class="sociablelast"><a rel="nofollow"  target="_blank" href="http://www.printfriendly.com/print?url=http%3A%2F%2Fwww.dealtaker.com%2Fblog%2F2010%2F02%2F25%2Fkohana-php-3-0-ko3-tutorial-part-5%2F&amp;partner=sociable" title="Print"><img src="http://www.dealtaker.com/blog/wp-content/plugins/sociable/images/printfriendly.png" title="Print" alt="Print" class="sociable-hovers" /></a></li>
</ul>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.dealtaker.com/blog/2010/02/25/kohana-php-3-0-ko3-tutorial-part-5/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>Kohana PHP 3.0 (KO3) Tutorial Part 4</title>
		<link>http://www.dealtaker.com/blog/2010/02/01/kohana-php-3-0-ko3-tutorial-part-4/</link>
		<comments>http://www.dealtaker.com/blog/2010/02/01/kohana-php-3-0-ko3-tutorial-part-4/#comments</comments>
		<pubDate>Mon, 01 Feb 2010 18:20:40 +0000</pubDate>
		<dc:creator>ellisgl</dc:creator>
				<category><![CDATA[technology]]></category>
		<category><![CDATA[framework]]></category>
		<category><![CDATA[KO3]]></category>
		<category><![CDATA[kohana]]></category>
		<category><![CDATA[models]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://www.dealtaker.com/blog/?p=1921</guid>
		<description><![CDATA[Welcome to the fourth part in this series on how to develop with Kohana PHP V3 (KO3). If you haven&#8217;t read any of previous parts yet, I would click here and read them before going on. In this tutorial we will be going over how work with models.

So you might be asking your self, what [...]]]></description>
			<content:encoded><![CDATA[<p>Welcome to the fourth part in this series on how to develop with Kohana PHP V3 (KO3). If you haven&#8217;t read any of previous parts yet, <a href="http://www.dealtaker.com/blog/tag/ko3/">I would click here and read them before going on</a>. In this tutorial we will be going over how work with models.<br />
<span id="more-1921"></span><br />
So you might be asking your self, what is a model. From <a href="http://docs.kohanaphp.com/">Kohana&#8217;s 2.x documents</a>:</p>
<blockquote cite="http://docs.kohanaphp.com/general/models"><p>Models are classes designed to work with information given by or asked for by the controller. For example, you have a guestbook, the controller will ask the model to retrieve the last ten entries, the model returns those entries to the controller who passes them on to a view. The controller might also send new entries to the model, update existing ones or even delete some.</p></blockquote>
<p>Simply a model is a data handler and manipulator.</p>
<p>The first thing we want to do is identify where and what the data is. Is it an XML feed, CSV, JSON, DB or something else? Well Iâ€™m going to make it easy. We are going to deal with our friend MySQL for this. The next step is to setup a MySQL DB connection.</p>
<p>Lets open up your bootstrap file (&#8221;application/bootstrap.php&#8221;) and find the like that reads &#8220;// &#8216;database&#8217;   =&gt; MODPATH.&#8217;database&#8217;,   // Database access&#8221; and uncomment it. The whole block of code should look like the following:</p>
<pre>Kohana::modules(array(
	// 'auth'       =&gt; MODPATH.'auth',       // Basic authentication
	// 'codebench'  =&gt; MODPATH.'codebench',  // Benchmarking tool
	 'database'   =&gt; MODPATH.'database',   // Database access
	// 'image'      =&gt; MODPATH.'image',      // Image manipulation
	// 'orm'        =&gt; MODPATH.'orm',        // Object Relationship Mapping
	// 'pagination' =&gt; MODPATH.'pagination', // Paging of results
	// 'userguide'  =&gt; MODPATH.'userguide',  // User guide and API documentation
	));</pre>
<p>Now save this. We&#8217;ve basically told the bootstrap to load the database module, but we need to configure it. Copy the &#8220;database.php&#8221; from &#8220;modules/database/config/&#8221; to &#8220;application/config/&#8221;. Open up the &#8220;application/config/database.php&#8221; file and edit accordingly to your settings. Mine looks like this:</p>
<pre>&lt;?php defined('SYSPATH') OR die('No direct access allowed.');

return array
(
	'default' =&gt; array
	(
		'type'       =&gt; 'mysql',
		'connection' =&gt; array(
			/**
			 * The following options are available for MySQL:
			 *
			 * string   hostname
			 * integer  port
			 * string   socket
			 * string   username
			 * string   password
			 * boolean  persistent
			 * string   database
			 */
			'hostname'   =&gt; 'localhost',
			'username'   =&gt; 'root',
			'password'   =&gt; FALSE,
			'persistent' =&gt; FALSE,
			'database'   =&gt; 'mykohana3',
		),
		'table_prefix' =&gt; '',
		'charset'      =&gt; 'utf8',
		'caching'      =&gt; FALSE,
		'profiling'    =&gt; TRUE,
	),
	'alternate' =&gt; array(
		'type'       =&gt; 'pdo',
		'connection' =&gt; array(
			/**
			 * The following options are available for PDO:
			 *
			 * string   dsn
			 * string   username
			 * string   password
			 * boolean  persistent
			 * string   identifier
			 */
			'dsn'        =&gt; 'mysql:host=localhost;dbname=mykohana3',
			'username'   =&gt; 'root',
			'password'   =&gt; FALSE,
			'persistent' =&gt; FALSE,
		),
		'table_prefix' =&gt; '',
		'charset'      =&gt; 'utf8',
		'caching'      =&gt; FALSE,
		'profiling'    =&gt; TRUE,
	),
);</pre>
<p>Save this. You&#8217;ll notice I have a database setup just this tutorial series named &#8220;mykohana3&#8243;, you might want to do the same if you can. Now that we have saved, let get a table set up. Here&#8217;s the SQL:</p>
<pre>CREATE TABLE `posts` (
  `id` MEDIUMINT(8) UNSIGNED NOT NULL AUTO_INCREMENT,
  `title` VARCHAR(255) DEFAULT NULL,
  `post` TEXT,
  PRIMARY KEY  (`id`)
) ENGINE=INNODB DEFAULT CHARSET=utf8 CHECKSUM=1 DELAY_KEY_WRITE=1 ROW_FORMAT=DYNAMIC;</pre>
<p>Go run that in your favorite MySQL client, I personally like <a href="http://code.google.com/p/sqlyog/">SQLYog</a>. You might have noticed the &#8220;charset&#8221; is set to &#8220;utf8&#8243; in both the config and create table statement. This will allow us to deal with i18n (Internationalization) stuff later on.</p>
<p>So let create a new folder under &#8220;application/classes&#8221; named &#8220;model&#8221;. Now lets create a new file and make it look like this:</p>
<pre>&lt;?php
defined('SYSPATH') or die('No direct script access.');

class Model_Post extends Kohana_Model
 {
    /**
     * Get the last 10 posts
     * @return ARRAY
     */
    public function getLastTenPosts()
     {
        $sql = 'SELECT *'."\n".
               'FROM   `posts`'."\n".
               'ORDER BY `id` DESC'."\n".
               'LIMIT  0, 10';

        return $this-&gt;_db-&gt;query(Database::SELECT, $sql, FALSE)
                         -&gt;as_array();
     }
 }</pre>
<p>Save this as &#8220;post.php&#8221; under &#8220;application/classes/model/&#8221;. Here&#8217;s an line by line explaination of the code.</p>
<pre>        $sql = 'SELECT *'."\n".
               'FROM   `posts`'."\n".
               'ORDER BY `id` DESC'."\n".
               'LIMIT  0, 10';</pre>
<p>This is a basic MySQL statement that selects up to ten rows from the DB which are sorted by the &#8216;id&#8217; in a descending direction.</p>
<pre>        return $this-&gt;_db-&gt;query(Database::SELECT, $sql, FALSE)
                         -&gt;as_array();</pre>
<p>This return array of the result from a query. The &#8220;query&#8221; method in this example take 3 parameters. 1st being what type of query, our being select, we use the constant &#8220;Database::SELECT&#8221;. There are 3 others,  &#8220;Database::INSERT&#8221;,  &#8220;Database::UPDATE&#8221; and &#8220;Database::DELETE&#8221;. The &#8220;as_array()&#8221; will return an array of the results, no having to do &#8220;while($row = mysql_fetch_array())&#8221;.</p>
<p>Now that we have a model method, I&#8217;m sure we would want to put it use. Open up &#8220;ko3.php&#8221; in &#8220;/application/classes/controller&#8221; and lets add this into the class:</p>
<pre>    public function action_posts()
     {
        $posts                            = new Model_Post();
        $ko3                              = array();
        $this-&gt;template-&gt;title            = 'Kohana 3.0 Model Test';
        $this-&gt;template-&gt;meta_keywords    = 'PHP, Kohana, KO3, Framework, Model';
        $this-&gt;template-&gt;meta_description = 'A test of of the KO3 framework Model';
        $this-&gt;template-&gt;styles           = array();
        $this-&gt;template-&gt;scripts          = array();

        // Get the last 10 posts
        $ko3['posts']                     = $posts-&gt;getLastTenPosts();
        $this-&gt;template-&gt;content          = View::factory('pages/posts', $ko3);

     }</pre>
<p>Basically we&#8217;ve called our model&#8217;s &#8220;getLastTenPosts()&#8221; method and assigned it to an array which we pass to our view. Talking about views, open up a new file and put the following into it:</p>
<pre>&lt;?php foreach($posts as $post):?&gt;
  &lt;h1&gt;&lt;?php echo $post['title'];?&gt;&lt;/h1&gt;
  &lt;?php echo $post['post'];?&gt;
 &lt;hr /&gt;
&lt;?php endforeach;?&gt;</pre>
<p>Save to as &#8220;posts.php&#8221; under &#8220;application/views/pages/&#8221;. This view loops through the array we pass to it from the the controller and displays our posts from the DB. Wait, what? There&#8217;s no posts in our DB! Here&#8217;s some SQL you can run to populate your table:</p>
<pre>insert  into `posts`(`id`,`title`,`post`) values (1,'Test Post','This is some sample text.');
insert  into `posts`(`id`,`title`,`post`) values (2,'Another post','Some more text');</pre>
<p>Now if you point your browser to &#8220;http://yourserver/mykohana3/ko3/posts&#8221; you should see the two entries on the screen.</p>
<p>Now lets add something to put data into our DB. Open the the post model (&#8221;application/classes/model/post.php&#8221;) and add this to the class:</p>
<pre>    public function addPost($title, $post)
     {
       $sql = sprintf('INSERT INTO `posts`'."\n".
                      'SET         `title` = %s,'."\n".
                      '            `post`  = %s',
                       $this-&gt;_db-&gt;escape($title),
                       $this-&gt;_db-&gt;escape($post));

       $this-&gt;_db-&gt;query(Database::INSERT, $sql, FALSE);
    }</pre>
<p>The above is a pretty simple insert, but you may notice we are using &#8220;$this-&gt;_db&gt;escape()&#8221;. This will wrap your strings in quotes and escape it content for you. Save it and now go back to the &#8220;posts.php&#8221; from &#8220;application/views/pages&#8221; and add the following to the bottom:</p>
<pre>&lt;form method="POST" action=""&gt;
  &lt;table&gt;
    &lt;tr&gt;
     &lt;td&gt;
       Title
     &lt;/td&gt;
     &lt;td&gt;
       &lt;input type="text" name="title" style="border: 1px solid #000000;"/&gt;
     &lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
     &lt;td&gt;
      Post
     &lt;/td&gt;
     &lt;td&gt;
      &lt;textarea cols="20" rows="5" name="post"&gt;&lt;/textarea&gt;
      &lt;input type="submit" name="submit" value="Submit"/&gt;
     &lt;/td&gt;
  &lt;/table&gt;
&lt;/form&gt;</pre>
<p>Save that and open the ko3 controller back up (&#8221;application/classes/controller/ko3.php&#8221;) and lets add a new method to it.</p>
<pre>    private function _addPost($title, $post_content)
     {
       // Load model
       $post = new Model_Post();

       // Check required fields
       if(empty($title))
        {
           return(array('error' =&gt; 'Please enter a title.'));
        }
       elseif(empty($post_content))
        {
           return(array('error' =&gt; 'Please enter a post.'));
        }

       // Add to DB
       $post-&gt;addPost($title, $post_content);
       return TRUE;
     }</pre>
<p>The above code is pretty much a middle man between the &#8220;action_posts&#8221; and the model that saves the post it self. Lets go back to the &#8220;action_posts&#8221; method and make it look like this:</p>
<pre>   public function action_posts()
     {
        // Load model
        $posts                            = new Model_Post();

        // Setup view stuff
        $ko3                              = array();
        $this-&gt;template-&gt;title            = 'Kohana 3.0 Model Test';
        $this-&gt;template-&gt;meta_keywords    = 'PHP, Kohana, KO3, Framework, Model';
        $this-&gt;template-&gt;meta_description = 'A test of of the KO3 framework Model';
        $this-&gt;template-&gt;styles           = array();
        $this-&gt;template-&gt;scripts          = array();
        $ko3['msg']                       = "";

        // Handle POST
        if($_POST)
         {
            $ret = $this-&gt;_addPost((isset($_POST['title']) ? $_POST['title'] : ""),
                                  (isset($_POST['post']) ? $_POST['post']  : ""));

            if(isset($ret['error']))
             {
                $ko3['msg'] = $ret['error'];
             }
            else
             {
                $ko3['msg'] = 'Saved.';
             }
         }

        // Get the last 10 posts
        $ko3['posts']                     = $posts-&gt;getLastTenPosts();

        // Display it.
        $this-&gt;template-&gt;content          = View::factory('pages/posts', $ko3);
     }</pre>
<p>Save this and reload your browser. Now you should see a pretty ugly form at bottom. Enter some stuff in and click the &#8220;submit&#8221; button. You post should appear at the top along with the word &#8220;Saved&#8221;, this is if you entered stuff in both fields, if not you should see an error.</p>
<p>Before I end this tutorial, I want to go back to our little model for saving our posts. There are several ways to do queries in KO3, but want to quickly show you how you can use the query builder to do the same thing.</p>
<pre>    public function addPost($title, $post)
     {
        DB::insert('posts', array('title','post'))
          -&gt;values(array($title, $post))
          -&gt;execute();
     }</pre>
<p>That&#8217;s pretty simple! It does the same thing as the previous one, with less &#8220;hassle&#8221; There are advantages using the query builder method, like being able to convert between different DB types (MySQL to Oracle to what ever).</p>
<p>While I might not have gone over doing updates with your model, I thought I would give you a homework assignment to see if you can come up with you own update model for this. Until next time when we go over &#8220;H&#8221; in &#8220;HMVC&#8221;, happy coding.</p>
<p>Sources used: <a href="http://kerkness.ca/wiki/doku.php" target="_blank">Unofficial Kohana 3 Wiki</a>, <a href="http://docs.kohanaphp.com/" target="_blank">Kohana PHP 2.x Docs</a>, <a href="http://v3.kohanaphp.com/guide/api" target="_blank">KO3 API Guide</a></p>
<p><a href="http://images.dealtaker.com/dealtaker/blog/ko3-tutorial/mykohana3_4.zip">Get the file for this tutorial here</a></p>

<div class="sociable">
<div class="sociable_tagline">
<strong>Share and Enjoy:</strong>
</div>
<ul>
	<li class="sociablefirst"><a rel="nofollow"  target="_blank" href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fwww.dealtaker.com%2Fblog%2F2010%2F02%2F01%2Fkohana-php-3-0-ko3-tutorial-part-4%2F&amp;title=Kohana%20PHP%203.0%20%28KO3%29%20Tutorial%20Part%204&amp;bodytext=Welcome%20to%20the%20fourth%20part%20in%20this%20series%20on%20how%20to%20develop%20with%20Kohana%20PHP%20V3%20%28KO3%29.%20If%20you%20haven%27t%20read%20any%20of%20previous%20parts%20yet%2C%20I%20would%20click%20here%20and%20read%20them%20before%20going%20on.%20In%20this%20tutorial%20we%20will%20be%20going%20over%20how%20work%20with%20models.%0D%0A%0D%0ASo%20" title="Digg"><img src="http://www.dealtaker.com/blog/wp-content/plugins/sociable/images/digg.png" title="Digg" alt="Digg" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://delicious.com/post?url=http%3A%2F%2Fwww.dealtaker.com%2Fblog%2F2010%2F02%2F01%2Fkohana-php-3-0-ko3-tutorial-part-4%2F&amp;title=Kohana%20PHP%203.0%20%28KO3%29%20Tutorial%20Part%204&amp;notes=Welcome%20to%20the%20fourth%20part%20in%20this%20series%20on%20how%20to%20develop%20with%20Kohana%20PHP%20V3%20%28KO3%29.%20If%20you%20haven%27t%20read%20any%20of%20previous%20parts%20yet%2C%20I%20would%20click%20here%20and%20read%20them%20before%20going%20on.%20In%20this%20tutorial%20we%20will%20be%20going%20over%20how%20work%20with%20models.%0D%0A%0D%0ASo%20" title="del.icio.us"><img src="http://www.dealtaker.com/blog/wp-content/plugins/sociable/images/delicious.png" title="del.icio.us" alt="del.icio.us" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://www.facebook.com/share.php?u=http%3A%2F%2Fwww.dealtaker.com%2Fblog%2F2010%2F02%2F01%2Fkohana-php-3-0-ko3-tutorial-part-4%2F&amp;t=Kohana%20PHP%203.0%20%28KO3%29%20Tutorial%20Part%204" title="Facebook"><img src="http://www.dealtaker.com/blog/wp-content/plugins/sociable/images/facebook.png" title="Facebook" alt="Facebook" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://twitter.com/home?status=Kohana%20PHP%203.0%20%28KO3%29%20Tutorial%20Part%204%20-%20http%3A%2F%2Fwww.dealtaker.com%2Fblog%2F2010%2F02%2F01%2Fkohana-php-3-0-ko3-tutorial-part-4%2F" title="Twitter"><img src="http://www.dealtaker.com/blog/wp-content/plugins/sociable/images/twitter.png" title="Twitter" alt="Twitter" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fwww.dealtaker.com%2Fblog%2F2010%2F02%2F01%2Fkohana-php-3-0-ko3-tutorial-part-4%2F&amp;title=Kohana%20PHP%203.0%20%28KO3%29%20Tutorial%20Part%204" title="StumbleUpon"><img src="http://www.dealtaker.com/blog/wp-content/plugins/sociable/images/stumbleupon.png" title="StumbleUpon" alt="StumbleUpon" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://www.mixx.com/submit?page_url=http%3A%2F%2Fwww.dealtaker.com%2Fblog%2F2010%2F02%2F01%2Fkohana-php-3-0-ko3-tutorial-part-4%2F&amp;title=Kohana%20PHP%203.0%20%28KO3%29%20Tutorial%20Part%204" title="Mixx"><img src="http://www.dealtaker.com/blog/wp-content/plugins/sociable/images/mixx.png" title="Mixx" alt="Mixx" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://www.google.com/bookmarks/mark?op=edit&amp;bkmk=http%3A%2F%2Fwww.dealtaker.com%2Fblog%2F2010%2F02%2F01%2Fkohana-php-3-0-ko3-tutorial-part-4%2F&amp;title=Kohana%20PHP%203.0%20%28KO3%29%20Tutorial%20Part%204&amp;annotation=Welcome%20to%20the%20fourth%20part%20in%20this%20series%20on%20how%20to%20develop%20with%20Kohana%20PHP%20V3%20%28KO3%29.%20If%20you%20haven%27t%20read%20any%20of%20previous%20parts%20yet%2C%20I%20would%20click%20here%20and%20read%20them%20before%20going%20on.%20In%20this%20tutorial%20we%20will%20be%20going%20over%20how%20work%20with%20models.%0D%0A%0D%0ASo%20" title="Google Bookmarks"><img src="http://www.dealtaker.com/blog/wp-content/plugins/sociable/images/googlebookmark.png" title="Google Bookmarks" alt="Google Bookmarks" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://reddit.com/submit?url=http%3A%2F%2Fwww.dealtaker.com%2Fblog%2F2010%2F02%2F01%2Fkohana-php-3-0-ko3-tutorial-part-4%2F&amp;title=Kohana%20PHP%203.0%20%28KO3%29%20Tutorial%20Part%204" title="Reddit"><img src="http://www.dealtaker.com/blog/wp-content/plugins/sociable/images/reddit.png" title="Reddit" alt="Reddit" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://technorati.com/faves?add=http%3A%2F%2Fwww.dealtaker.com%2Fblog%2F2010%2F02%2F01%2Fkohana-php-3-0-ko3-tutorial-part-4%2F" title="Technorati"><img src="http://www.dealtaker.com/blog/wp-content/plugins/sociable/images/technorati.png" title="Technorati" alt="Technorati" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://buzz.yahoo.com/submit/?submitUrl=http%3A%2F%2Fwww.dealtaker.com%2Fblog%2F2010%2F02%2F01%2Fkohana-php-3-0-ko3-tutorial-part-4%2F&amp;submitHeadline=Kohana%20PHP%203.0%20%28KO3%29%20Tutorial%20Part%204&amp;submitSummary=Welcome%20to%20the%20fourth%20part%20in%20this%20series%20on%20how%20to%20develop%20with%20Kohana%20PHP%20V3%20%28KO3%29.%20If%20you%20haven%27t%20read%20any%20of%20previous%20parts%20yet%2C%20I%20would%20click%20here%20and%20read%20them%20before%20going%20on.%20In%20this%20tutorial%20we%20will%20be%20going%20over%20how%20work%20with%20models.%0D%0A%0D%0ASo%20&amp;submitCategory=science&amp;submitAssetType=text" title="Yahoo! Buzz"><img src="http://www.dealtaker.com/blog/wp-content/plugins/sociable/images/yahoobuzz.png" title="Yahoo! Buzz" alt="Yahoo! Buzz" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://www.myspace.com/Modules/PostTo/Pages/?u=http%3A%2F%2Fwww.dealtaker.com%2Fblog%2F2010%2F02%2F01%2Fkohana-php-3-0-ko3-tutorial-part-4%2F&amp;t=Kohana%20PHP%203.0%20%28KO3%29%20Tutorial%20Part%204" title="MySpace"><img src="http://www.dealtaker.com/blog/wp-content/plugins/sociable/images/myspace.png" title="MySpace" alt="MySpace" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://www.linkedin.com/shareArticle?mini=true&amp;url=http%3A%2F%2Fwww.dealtaker.com%2Fblog%2F2010%2F02%2F01%2Fkohana-php-3-0-ko3-tutorial-part-4%2F&amp;title=Kohana%20PHP%203.0%20%28KO3%29%20Tutorial%20Part%204&amp;source=Inside+DealTaker+All+Things+Deal+Oriented&amp;summary=Welcome%20to%20the%20fourth%20part%20in%20this%20series%20on%20how%20to%20develop%20with%20Kohana%20PHP%20V3%20%28KO3%29.%20If%20you%20haven%27t%20read%20any%20of%20previous%20parts%20yet%2C%20I%20would%20click%20here%20and%20read%20them%20before%20going%20on.%20In%20this%20tutorial%20we%20will%20be%20going%20over%20how%20work%20with%20models.%0D%0A%0D%0ASo%20" title="LinkedIn"><img src="http://www.dealtaker.com/blog/wp-content/plugins/sociable/images/linkedin.png" title="LinkedIn" alt="LinkedIn" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="https://favorites.live.com/quickadd.aspx?marklet=1&amp;url=http%3A%2F%2Fwww.dealtaker.com%2Fblog%2F2010%2F02%2F01%2Fkohana-php-3-0-ko3-tutorial-part-4%2F&amp;title=Kohana%20PHP%203.0%20%28KO3%29%20Tutorial%20Part%204" title="Live"><img src="http://www.dealtaker.com/blog/wp-content/plugins/sociable/images/live.png" title="Live" alt="Live" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="mailto:?subject=Kohana%20PHP%203.0%20%28KO3%29%20Tutorial%20Part%204&amp;body=http%3A%2F%2Fwww.dealtaker.com%2Fblog%2F2010%2F02%2F01%2Fkohana-php-3-0-ko3-tutorial-part-4%2F" title="email"><img src="http://www.dealtaker.com/blog/wp-content/plugins/sociable/images/email_link.png" title="email" alt="email" class="sociable-hovers" /></a></li>
	<li class="sociablelast"><a rel="nofollow"  target="_blank" href="http://www.printfriendly.com/print?url=http%3A%2F%2Fwww.dealtaker.com%2Fblog%2F2010%2F02%2F01%2Fkohana-php-3-0-ko3-tutorial-part-4%2F&amp;partner=sociable" title="Print"><img src="http://www.dealtaker.com/blog/wp-content/plugins/sociable/images/printfriendly.png" title="Print" alt="Print" class="sociable-hovers" /></a></li>
</ul>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.dealtaker.com/blog/2010/02/01/kohana-php-3-0-ko3-tutorial-part-4/feed/</wfw:commentRss>
		<slash:comments>22</slash:comments>
		</item>
		<item>
		<title>Kohana PHP 3.0 (KO3) Tutorial Part 3</title>
		<link>http://www.dealtaker.com/blog/2009/12/30/kohana-php-3-0-ko3-tutorial-part-3/</link>
		<comments>http://www.dealtaker.com/blog/2009/12/30/kohana-php-3-0-ko3-tutorial-part-3/#comments</comments>
		<pubDate>Wed, 30 Dec 2009 15:08:30 +0000</pubDate>
		<dc:creator>ellisgl</dc:creator>
				<category><![CDATA[technology]]></category>
		<category><![CDATA[framework]]></category>
		<category><![CDATA[how-to]]></category>
		<category><![CDATA[howto]]></category>
		<category><![CDATA[KO3]]></category>
		<category><![CDATA[kohana]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://www.dealtaker.com/blog/?p=1873</guid>
		<description><![CDATA[Welcome to the third part in this series on how to develop with Kohana PHP V3 (KO3). If you havenâ€™t read the first and/or second parts yet, I would click here and read them before going on. In this tutorial we will be going over how to create a template.

In the last tutorial, we went [...]]]></description>
			<content:encoded><![CDATA[<p>Welcome to the third part in this series on how to develop with Kohana PHP V3 (KO3). If you havenâ€™t read the <a href="http://www.dealtaker.com/blog/2009/11/20/kohana-php-3-0-ko3-tutorial-part-1/" target="_blank">first</a> and/or <a href="http://www.dealtaker.com/blog/2009/12/07/kohana-php-3-0-ko3-tutorial-part-2/" target="_blank">second parts</a> yet, I would click here and read them before going on. In this tutorial we will be going over how to create a template.<br />
<span id="more-1873"></span><br />
In the last tutorial, we went over views and in this one we are going to extend the Controller classes which will allow us to create a template. A template, you might ask, is nothing more than a view that is more or less your base (X)HTML code. This will allow to keep things &#8220;DRY&#8221; in the view world. Before we get to putting code into a file, lets create a new directory under &#8220;/application/views/&#8221; named &#8220;templates&#8221;.  Now open up your favorite IDE and make a new file and put the following into it:</p>
<pre>
&lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Transitional//EN&quot;
&quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&quot;&gt;
&lt;html xmlns=&quot;http://www.w3.org/1999/xhtml&quot; xml:lang=&quot;en&quot; lang=&quot;en&quot;&gt;
  &lt;head&gt;
    &lt;meta http-equiv=&quot;Content-type&quot; content=&quot;text/html; charset=UTF-8&quot; /&gt;
    &lt;meta http-equiv=&quot;Content-Language&quot; content=&quot;en-us&quot; /&gt;
    &lt;title&gt;&lt;?php echo $title;?&gt;&lt;/title&gt;
    &lt;meta name=&quot;keywords&quot; content=&quot;&lt;?php echo $meta_keywords;?&gt;&quot; /&gt;
    &lt;meta name=&quot;description&quot; content=&quot;&lt;?php echo $meta_description;?&gt;&quot; /&gt;
    &lt;meta name=&quot;copyright&quot; content=&quot;&lt;?php echo $meta_copywrite;?&gt;&quot; /&gt;
    &lt;?php foreach($styles as $file =&gt; $type) { echo HTML::style($file, array('media' =&gt; $type)), &quot;\n&quot;; }?&gt;
    &lt;?php foreach($scripts as $file) { echo HTML::script($file), &quot;\n&quot;; }?&gt;
  &lt;/head&gt;
  &lt;body&gt;
    &lt;div id=&quot;container&quot;&gt;
     &lt;?php echo $header;?&gt;
     &lt;?php echo $content;?&gt;
     &lt;?php echo $footer;?&gt;
    &lt;/div&gt;
  &lt;/body&gt;
&lt;/html&gt;
</pre>
<p>Save the above as &#8220;default.php&#8221; in your &#8220;/application/views/templates/&#8221; folder. </p>
<p>As you can see the above pretty much looks like a view we have done before, a bit more expanded. I will go over the &#8220;foreach&#8221; a little bit later. Unlike a view, this will most likely be used by all of your project. Since we will point to this file for our template, or shell, this will reduce the amount of code you have to put in each view, keeping thing separated, easier to maintain, or basically &#8220;DRY&#8221;.</p>
<p>Now that we have a template, our system isn&#8217;t going to do anything with it until well tell it to use it. So lets go back to our IDE and create a new file and put the following into it:</p>
<pre>
&lt;?php
 defined('SYSPATH') or die('No direct script access.');

 class Controller_DefaultTemplate extends Controller_Template
  {
     public $template = 'templates/default';

     /**
      * Initialize properties before running the controller methods (actions),
      * so they are available to our action.
      */
     public function before()
      {
         // Run anything that need ot run before this.
         parent::before();

         if($this-&gt;auto_render)
          {
            // Initialize empty values
            $this-&gt;template-&gt;title            = '';
            $this-&gt;template-&gt;meta_keywords    = '';
            $this-&gt;template-&gt;meta_description = '';
            $this-&gt;template-&gt;meta_copywrite   = '';
            $this-&gt;template-&gt;header           = '';
            $this-&gt;template-&gt;content          = '';
            $this-&gt;template-&gt;footer           = '';
            $this-&gt;template-&gt;styles           = array();
            $this-&gt;template-&gt;scripts          = array();
          }
      }

     /**
      * Fill in default values for our properties before rendering the output.
      */
     public function after()
      {
         if($this-&gt;auto_render)
          {
             // Define defaults
             $styles                  = array('assets/css/reset.css' =&gt; 'screen');
             $scripts                 = array('http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js');

             // Add defaults to template variables.
             $this-&gt;template-&gt;styles  = array_reverse(array_merge($this-&gt;template-&gt;styles, $styles));
             $this-&gt;template-&gt;scripts = array_reverse(array_merge($this-&gt;template-&gt;scripts, $scripts));
           }

         // Run anything that needs to run after this.
         parent::after();
      }
 }
</pre>
<p>And save this as &#8220;defaulttemplate.php&#8221; under your &#8220;/application/classes/controller/&#8221; folder.</p>
<p>The above code extends the &#8220;Controller_Template&#8221; class and does three main things, initialize some properties (variables) to be accessable by our methods (actions) and appends default values to them and then gets associates them to our template variables before we render the final output to the screen. This is where the foreach() loop in the template comes into play. The foreach() loop uses a static method for the helper class &#8220;HTML&#8221;, one to <a href="http://v3.kohanaphp.com/guide/api/HTML#style" target="_blank">load CSS style sheets</a> and one to <a href="http://v3.kohanaphp.com/guide/api/HTML#script" target="_blank">load JS files</a>. Both of these helper methods will iterate through an array and properly wrap it in the appropriate tag. They can take a path or a URL. </p>
<p>You might be wondering what a &#8220;Helper&#8221; is, so here is a quick definition from the Kohana PHP 2.x documents:</p>
<blockquote cite="http://docs.kohanaphp.com/general/helpers"><p>
Helpers are simply &#8220;handy&#8221; functions that help you with development.</p>
<p>Helpers are similar to library methods, but there is a subtle difference. With a library, you have to create an instance of the library&#8217;s class to use its methods. Helpers are declared as static methods of a class, so there is no need to instantiate the class. You can think of them as â€œglobal functionsâ€.</p>
<p>As with libraries, the helper classes are automatically loaded by the framework when they are used, so there is no need to load them yourself.
</p></blockquote>
<p>OK, back on course. You might have noticed there is a reference to &#8220;assets/css/reset.css&#8221;, so lets go ahead and get that in place. In your root create a folder named &#8220;assets&#8221; and in that folder create one named &#8220;css&#8221;. For the actual &#8220;reset.css&#8221; file, I went to <a href="http://serenedestiny.com/" target="blank">Serene Destiny</a> and copied the code from the article titled &#8220;<a href="http://serenedestiny.com/blog/2009/04/open-thread-create-the-perfect-css-reset/" target="_blank">Create The Perfect CSS Reset</a>&#8221; into a file and saved it as &#8220;reset.css&#8221; in the &#8220;assets/css/&#8221; folder. You might want to also set up some other folders within &#8220;/assets/&#8221;, maybe &#8220;images&#8221;, &#8220;js&#8221; and &#8220;files&#8221;. Basically the assets folder should be used to store and organize static files and such.</p>
<p>At this point, our application still doesn&#8217;t know what to do what we have done, so we need to modify our controller. So open &#8220;/application/classes/controller/ko3.php&#8221;.<br />
We want to change what class we are extending, so change the line:</p>
<pre>class Controller_Ko3 extends Controller</pre>
<p>to:</p>
<pre>lass Controller_Ko3 extends Controller_DefaultTemplate</pre>
<p>We also need to change up our &#8220;index&#8221; action (action_index() method) to look like the following:</p>
<pre>
    public function action_index()
     {
        $ko3_inner               = array();
        $ko3                     = array();
        $this-&gt;template-&gt;title   = 'Kohana 3.0';

        View::set_global('x', 'This is a global variable');

        $ko3_inner['content']    = 'We have more data';
        $ko3['content']          = 'We have data';
        $ko3['ko3_inner']        = View::factory('blocks/ko3_inner', $ko3_inner)
                                       -&gt;render();
        $this-&gt;template-&gt;content = View::factory('pages/ko3', $ko3);
     }
</pre>
<p>Save it. Now you might noticed that we now have &#8220;$this-&gt;template-&gt;title   = &#8216;Kohana 3.0&#8242;;&#8221;, this will assign a value to our templates &#8220;title&#8221; variable. The next thing you might notice is the absence of the last &#8220;render()&#8221; method. The &#8220;factory()&#8221; method actually will &#8220;auto render&#8221; it to our template&#8217;s &#8220;content&#8221; variable. Pretty simple, yes?</p>
<p>There is something we should probably do before loading up the page, so load up the &#8220;ko3.php&#8221; view file located in &#8220;application/views/pages/&#8221;. You might noticed that we have all the &#8220;shell&#8221; code in our view, so lets remove it. What you should only have in the view file is this:</p>
<pre>
  &lt;h1&gt;This is my first view&lt;/h1&gt;
  &lt;?php echo $content;?&gt;
  &lt;?php echo $ko3_inner; ?&gt;
  &lt;br/&gt;&lt;?php echo $x;?&gt;
</pre>
<p>Now if you load it up, you should see that page has a title of &#8220;Kohana 3.0&#8243; and the page should pretty much look the same as it did from the last tutorial. If you view the source thou, it would look much different. But you might be wondering about the other variables in the template and what to do with them. OK, let go back and edit our &#8220;index&#8221; action again. Make it look like:</p>
<pre>
    public function action_index()
     {
        $ko3_inner                        = array();
        $ko3                              = array();
        $this-&gt;template-&gt;title            = 'Kohana 3.0';
        $this-&gt;template-&gt;meta_keywords    = 'PHP, Kohana, KO3, Framework';
        $this-&gt;template-&gt;meta_description = 'A test of of the KO3 framework';
        $this-&gt;template-&gt;styles           = array('assets/css/red.css' =&gt; 'screen');
        $this-&gt;template-&gt;scripts          = array('assets/js/jqtest.js', NULL, TRUE);

        View::set_global('x', 'This is a global variable');

        $ko3_inner['content']             = 'We have more data';
        $ko3['content']                   = 'We have data';
        $ko3['ko3_inner']                 = View::factory('blocks/ko3_inner', $ko3_inner)
                                                -&gt;render();
        $this-&gt;template-&gt;content          = View::factory('pages/ko3', $ko3);
     }
</pre>
<p>Pretty simple. You will notice I didn&#8217;t fill in the header or footer. I&#8217;m sure you know what to do there. Hint: Render a view to that variable =). Another thing you might notice is that I have put in &#8220;assets/css/red.css&#8221; and &#8220;assets/css/jqtest.js&#8221;. Lets make those two files starting with &#8220;/assets/css/red.css&#8221;:</p>
<pre>
h1
 {
    color: #FF0000;
 }
</pre>
<p>Next &#8220;/assets/js/jqtest.js&#8221;:</p>
<pre>
$("document").ready(function()
                     {
                        alert('Hello Kohana!');
                     });
</pre>
<p>Save them and refresh the site. You should see an alert pop up and the first line of text in red.</p>
<p>Today we have created a template file, extended a template controller and our controller use that template file. There is a lot of potential with what you could do with this already. So until next time when I will go over models, happy coding!<br />
Sources used: <a href="http://kerkness.ca/wiki/doku.php" target="_blank">Unofficial Kohana 3 Wiki</a>, <a href="http://docs.kohanaphp.com/" target="_blank">Kohana PHP 2.x Docs</a></p>
<p><a href="http://images.dealtaker.com/dealtaker/blog/ko3-tutorial/mykohana3_3.zip">Get the file for this tutorial here</a></p>

<div class="sociable">
<div class="sociable_tagline">
<strong>Share and Enjoy:</strong>
</div>
<ul>
	<li class="sociablefirst"><a rel="nofollow"  target="_blank" href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fwww.dealtaker.com%2Fblog%2F2009%2F12%2F30%2Fkohana-php-3-0-ko3-tutorial-part-3%2F&amp;title=Kohana%20PHP%203.0%20%28KO3%29%20Tutorial%20Part%203&amp;bodytext=Welcome%20to%20the%20third%20part%20in%20this%20series%20on%20how%20to%20develop%20with%20Kohana%20PHP%20V3%20%28KO3%29.%20If%20you%20haven%C3%A2%E2%82%AC%E2%84%A2t%20read%20the%20first%20and%2For%20second%20parts%20yet%2C%20I%20would%20click%20here%20and%20read%20them%20before%20going%20on.%20In%20this%20tutorial%20we%20will%20be%20going%20over%20how%20to%20create%20" title="Digg"><img src="http://www.dealtaker.com/blog/wp-content/plugins/sociable/images/digg.png" title="Digg" alt="Digg" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://delicious.com/post?url=http%3A%2F%2Fwww.dealtaker.com%2Fblog%2F2009%2F12%2F30%2Fkohana-php-3-0-ko3-tutorial-part-3%2F&amp;title=Kohana%20PHP%203.0%20%28KO3%29%20Tutorial%20Part%203&amp;notes=Welcome%20to%20the%20third%20part%20in%20this%20series%20on%20how%20to%20develop%20with%20Kohana%20PHP%20V3%20%28KO3%29.%20If%20you%20haven%C3%A2%E2%82%AC%E2%84%A2t%20read%20the%20first%20and%2For%20second%20parts%20yet%2C%20I%20would%20click%20here%20and%20read%20them%20before%20going%20on.%20In%20this%20tutorial%20we%20will%20be%20going%20over%20how%20to%20create%20" title="del.icio.us"><img src="http://www.dealtaker.com/blog/wp-content/plugins/sociable/images/delicious.png" title="del.icio.us" alt="del.icio.us" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://www.facebook.com/share.php?u=http%3A%2F%2Fwww.dealtaker.com%2Fblog%2F2009%2F12%2F30%2Fkohana-php-3-0-ko3-tutorial-part-3%2F&amp;t=Kohana%20PHP%203.0%20%28KO3%29%20Tutorial%20Part%203" title="Facebook"><img src="http://www.dealtaker.com/blog/wp-content/plugins/sociable/images/facebook.png" title="Facebook" alt="Facebook" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://twitter.com/home?status=Kohana%20PHP%203.0%20%28KO3%29%20Tutorial%20Part%203%20-%20http%3A%2F%2Fwww.dealtaker.com%2Fblog%2F2009%2F12%2F30%2Fkohana-php-3-0-ko3-tutorial-part-3%2F" title="Twitter"><img src="http://www.dealtaker.com/blog/wp-content/plugins/sociable/images/twitter.png" title="Twitter" alt="Twitter" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fwww.dealtaker.com%2Fblog%2F2009%2F12%2F30%2Fkohana-php-3-0-ko3-tutorial-part-3%2F&amp;title=Kohana%20PHP%203.0%20%28KO3%29%20Tutorial%20Part%203" title="StumbleUpon"><img src="http://www.dealtaker.com/blog/wp-content/plugins/sociable/images/stumbleupon.png" title="StumbleUpon" alt="StumbleUpon" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://www.mixx.com/submit?page_url=http%3A%2F%2Fwww.dealtaker.com%2Fblog%2F2009%2F12%2F30%2Fkohana-php-3-0-ko3-tutorial-part-3%2F&amp;title=Kohana%20PHP%203.0%20%28KO3%29%20Tutorial%20Part%203" title="Mixx"><img src="http://www.dealtaker.com/blog/wp-content/plugins/sociable/images/mixx.png" title="Mixx" alt="Mixx" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://www.google.com/bookmarks/mark?op=edit&amp;bkmk=http%3A%2F%2Fwww.dealtaker.com%2Fblog%2F2009%2F12%2F30%2Fkohana-php-3-0-ko3-tutorial-part-3%2F&amp;title=Kohana%20PHP%203.0%20%28KO3%29%20Tutorial%20Part%203&amp;annotation=Welcome%20to%20the%20third%20part%20in%20this%20series%20on%20how%20to%20develop%20with%20Kohana%20PHP%20V3%20%28KO3%29.%20If%20you%20haven%C3%A2%E2%82%AC%E2%84%A2t%20read%20the%20first%20and%2For%20second%20parts%20yet%2C%20I%20would%20click%20here%20and%20read%20them%20before%20going%20on.%20In%20this%20tutorial%20we%20will%20be%20going%20over%20how%20to%20create%20" title="Google Bookmarks"><img src="http://www.dealtaker.com/blog/wp-content/plugins/sociable/images/googlebookmark.png" title="Google Bookmarks" alt="Google Bookmarks" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://reddit.com/submit?url=http%3A%2F%2Fwww.dealtaker.com%2Fblog%2F2009%2F12%2F30%2Fkohana-php-3-0-ko3-tutorial-part-3%2F&amp;title=Kohana%20PHP%203.0%20%28KO3%29%20Tutorial%20Part%203" title="Reddit"><img src="http://www.dealtaker.com/blog/wp-content/plugins/sociable/images/reddit.png" title="Reddit" alt="Reddit" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://technorati.com/faves?add=http%3A%2F%2Fwww.dealtaker.com%2Fblog%2F2009%2F12%2F30%2Fkohana-php-3-0-ko3-tutorial-part-3%2F" title="Technorati"><img src="http://www.dealtaker.com/blog/wp-content/plugins/sociable/images/technorati.png" title="Technorati" alt="Technorati" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://buzz.yahoo.com/submit/?submitUrl=http%3A%2F%2Fwww.dealtaker.com%2Fblog%2F2009%2F12%2F30%2Fkohana-php-3-0-ko3-tutorial-part-3%2F&amp;submitHeadline=Kohana%20PHP%203.0%20%28KO3%29%20Tutorial%20Part%203&amp;submitSummary=Welcome%20to%20the%20third%20part%20in%20this%20series%20on%20how%20to%20develop%20with%20Kohana%20PHP%20V3%20%28KO3%29.%20If%20you%20haven%C3%A2%E2%82%AC%E2%84%A2t%20read%20the%20first%20and%2For%20second%20parts%20yet%2C%20I%20would%20click%20here%20and%20read%20them%20before%20going%20on.%20In%20this%20tutorial%20we%20will%20be%20going%20over%20how%20to%20create%20&amp;submitCategory=science&amp;submitAssetType=text" title="Yahoo! Buzz"><img src="http://www.dealtaker.com/blog/wp-content/plugins/sociable/images/yahoobuzz.png" title="Yahoo! Buzz" alt="Yahoo! Buzz" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://www.myspace.com/Modules/PostTo/Pages/?u=http%3A%2F%2Fwww.dealtaker.com%2Fblog%2F2009%2F12%2F30%2Fkohana-php-3-0-ko3-tutorial-part-3%2F&amp;t=Kohana%20PHP%203.0%20%28KO3%29%20Tutorial%20Part%203" title="MySpace"><img src="http://www.dealtaker.com/blog/wp-content/plugins/sociable/images/myspace.png" title="MySpace" alt="MySpace" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://www.linkedin.com/shareArticle?mini=true&amp;url=http%3A%2F%2Fwww.dealtaker.com%2Fblog%2F2009%2F12%2F30%2Fkohana-php-3-0-ko3-tutorial-part-3%2F&amp;title=Kohana%20PHP%203.0%20%28KO3%29%20Tutorial%20Part%203&amp;source=Inside+DealTaker+All+Things+Deal+Oriented&amp;summary=Welcome%20to%20the%20third%20part%20in%20this%20series%20on%20how%20to%20develop%20with%20Kohana%20PHP%20V3%20%28KO3%29.%20If%20you%20haven%C3%A2%E2%82%AC%E2%84%A2t%20read%20the%20first%20and%2For%20second%20parts%20yet%2C%20I%20would%20click%20here%20and%20read%20them%20before%20going%20on.%20In%20this%20tutorial%20we%20will%20be%20going%20over%20how%20to%20create%20" title="LinkedIn"><img src="http://www.dealtaker.com/blog/wp-content/plugins/sociable/images/linkedin.png" title="LinkedIn" alt="LinkedIn" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="https://favorites.live.com/quickadd.aspx?marklet=1&amp;url=http%3A%2F%2Fwww.dealtaker.com%2Fblog%2F2009%2F12%2F30%2Fkohana-php-3-0-ko3-tutorial-part-3%2F&amp;title=Kohana%20PHP%203.0%20%28KO3%29%20Tutorial%20Part%203" title="Live"><img src="http://www.dealtaker.com/blog/wp-content/plugins/sociable/images/live.png" title="Live" alt="Live" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="mailto:?subject=Kohana%20PHP%203.0%20%28KO3%29%20Tutorial%20Part%203&amp;body=http%3A%2F%2Fwww.dealtaker.com%2Fblog%2F2009%2F12%2F30%2Fkohana-php-3-0-ko3-tutorial-part-3%2F" title="email"><img src="http://www.dealtaker.com/blog/wp-content/plugins/sociable/images/email_link.png" title="email" alt="email" class="sociable-hovers" /></a></li>
	<li class="sociablelast"><a rel="nofollow"  target="_blank" href="http://www.printfriendly.com/print?url=http%3A%2F%2Fwww.dealtaker.com%2Fblog%2F2009%2F12%2F30%2Fkohana-php-3-0-ko3-tutorial-part-3%2F&amp;partner=sociable" title="Print"><img src="http://www.dealtaker.com/blog/wp-content/plugins/sociable/images/printfriendly.png" title="Print" alt="Print" class="sociable-hovers" /></a></li>
</ul>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.dealtaker.com/blog/2009/12/30/kohana-php-3-0-ko3-tutorial-part-3/feed/</wfw:commentRss>
		<slash:comments>15</slash:comments>
		</item>
		<item>
		<title>Kohana PHP 3.0 (KO3) Tutorial Part 2</title>
		<link>http://www.dealtaker.com/blog/2009/12/07/kohana-php-3-0-ko3-tutorial-part-2/</link>
		<comments>http://www.dealtaker.com/blog/2009/12/07/kohana-php-3-0-ko3-tutorial-part-2/#comments</comments>
		<pubDate>Mon, 07 Dec 2009 15:47:54 +0000</pubDate>
		<dc:creator>ellisgl</dc:creator>
				<category><![CDATA[technology]]></category>
		<category><![CDATA[framework]]></category>
		<category><![CDATA[KO3]]></category>
		<category><![CDATA[kohana]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[views]]></category>

		<guid isPermaLink="false">http://www.dealtaker.com/blog/?p=1835</guid>
		<description><![CDATA[Welcome to the second part in this series on how to develop with Kohana PHP V3 (KO3). If you havenâ€™t read the first part, I would click here and read it before going on. In this tutorial we will be going over how to develop views.

Before we get into views, we&#8217;ll want to update the [...]]]></description>
			<content:encoded><![CDATA[<p>Welcome to the second part in this series on how to develop with Kohana PHP V3 (<acronym title="Kohana PHP 3">KO3</acronym>). If you havenâ€™t read the first part, I would <a href="http://www.dealtaker.com/blog/2009/11/20/kohana-php-3-0-ko3-tutorial-part-1/">click here</a> and read it before going on. In this tutorial we will be going over how to develop views.<br />
<span id="more-1835"></span><br />
Before we get into views, we&#8217;ll want to update the KO3 code base, So point your browser to <a href="http://dev.kohanaphp.com/projects/kohana3/files">http://dev.kohanaphp.com/projects/kohana3/files</a>, download it, open it and extract everything inside the &#8220;kohana&#8221; folder to &#8220;mykohana3&#8243;. Once you have done that, delete or rename the &#8220;install.php&#8221; in your &#8220;mykohana3&#8243; folder. Next, open up the &#8220;bootstrap.php&#8221; file in the &#8220;application&#8221; folder and change the following line:</p>
<pre>Kohana::init(array('base_url' =&gt; '/kohana/'));</pre>
<p>to</p>
<pre>Kohana::init(array('base_url'   =&gt; '/mykohana3/',
                   'index_file' =&gt; ''));</pre>
<p>Now that we are updated to the latest and greatest, lets get right in to developing a view. Create a new folder within the &#8220;application&#8221; folder named &#8220;views&#8221; and inside the &#8220;views&#8221; folder, create another folder named &#8220;pages&#8221;. Now open up a new document in your editor and put the following in it:</p>
<pre>&lt;html&gt;
 &lt;head&gt;
  &lt;title&gt;Hello!&lt;/title&gt;
 &lt;/head&gt;
 &lt;body&gt;
  &lt;h1&gt;This is my first view&lt;/h1&gt;
 &lt;/body&gt;
&lt;/html&gt;</pre>
<p>Now save that in your &#8220;application/views/pages&#8221; as &#8220;ko3.php&#8221;. As you can tell, it&#8217;s a pretty simple HTML page with some PHP mixed in. Lets open the &#8220;ko3&#8243; controller (&#8221;application/classes/controller/ko3.php&#8221;). Replace the &#8220;action_index&#8221; class with the following:</p>
<pre>    public function action_index()
     {
        $this-&gt;request-&gt;response = View::factory('pages/ko3');
     }</pre>
<p>Save it, and load up &#8220;http://yourserver/myfirstkohana3/&#8221; in your browser. You should see &#8220;This is my first view&#8221;. The code above is pretty simple, we use the &#8220;Facotry&#8221; method of the view class to load the file &#8220;application/views/pages/ko3.php&#8221;, renders it and outputs it. Not very exciting, so let go back to the view (&#8221;application/views/pages/ko3.php&#8221;) and add:</p>
<pre>  &lt;?php echo $content;?&gt;</pre>
<p>After the &#8220;h1&#8243; tags. Your view should look like this:</p>
<pre>&lt;html&gt;
 &lt;head&gt;
  &lt;title&gt;Hello!&lt;/title&gt;
 &lt;/head&gt;
 &lt;body&gt;
  &lt;h1&gt;This is my first view&lt;/h1&gt;
  &lt;?php echo $content;?&gt;
 &lt;/body&gt;
&lt;/html&gt;</pre>
<p>If we were to refresh the browser, we would seen an exception error about an undefined variable. So let&#8217;s go ahead and fix that, by relating data to the view variable in our controller. So, change up &#8220;Action_Index&#8221; controller to look like this:</p>
<pre>    public function action_index()
     {
        $view                       = View::factory('pages/ko3');
        $view-&gt;content              = 'We have data!';
        $this-&gt;request-&gt;response = $view-&gt;render();
     }</pre>
<p>Now if we refresh the browser, we should see &#8220;This is my first view&#8221; and under that &#8220;We have data!&#8221;. Lets explain the the code line by line.</p>
<pre>$view = View::factory('pages/ko3');</pre>
<p>This load our view file (&#8221;application/views/pages/ko3.php&#8221;) into the view controller.</p>
<pre>$view-&gt;content = 'We have data!';</pre>
<p>This assigns a variable for use by the view called &#8220;content&#8221; and we also assign data to that, in this case it&#8217;s &#8220;We have data!&#8221;</p>
<pre>$this-&gt;request-&gt;response = $view-&gt;render();</pre>
<p>This renders the view and outputs it.</p>
<p>Simple enough, but there is another way of doing the above. We could have also done the following:</p>
<pre>    public function action_index()
     {
        $data['content']         = 'We have data!';
        $view                    = View::factory('pages/ko3', $data);
        $this-&gt;request-&gt;response = $view-&gt;render();
     }</pre>
<p>Basically the above use an array with element keys as the template variable names to assign the data. We are not done yet! There&#8217;s 2 more ways we can do the above.</p>
<pre>    public function action_index()
     {
        $view                    = View::factory('pages/ko3')
                                       -&gt;set('content', 'We have data!');

        $this-&gt;request-&gt;response = $view-&gt;render();
     }</pre>
<p>The above used the set method of the view class, which you can use method chaining to set all your template variables. And now for forth way:</p>
<pre>    public function action_index()
     {
        $content                 = 'We have data!';
        $view                    = View::factory('pages/ko3')
                                       -&gt;bind('content', $content);
        $this-&gt;request-&gt;response = $view-&gt;render();
     }</pre>
<p>Now the above is using the bind method of the view class. Once again, this you can do method chaining here. This is a little bit different from the set method, since it will create a reference to a variable. So $content might equal &#8216;We have data!&#8217; when we bound the variable to the template variable, but could change later on, since we are referencing the variable $content in our controller, instead of assigning data to the template variable.</p>
<p>If we were to do the following:</p>
<pre>    public function action_index()
     {
        $content                 = 'We have data!';
        $view                    = View::factory('pages/ko3')
                                       -&gt;bind('content', $content);
        $content                 = 'Our data changed';
        $this-&gt;request-&gt;response = $view-&gt;render();
     }</pre>
<p>Instead of &#8220;We have data!&#8221; showing on our screen, we would have &#8220;Our data changed&#8221;.</p>
<p>Now lets do a view with in a view! Create a new folder in your &#8220;application/views/&#8221; named &#8220;blocks&#8221;. Lets create another view file named &#8220;ko3_inner.php&#8221; and put this in it:</p>
<pre>  &lt;h3&gt;This is an inner view&lt;/h3&gt;</pre>
<p>Save that in your &#8220;application/views/blocks/&#8221; directory. Now lets edit the &#8220;ko3&#8243; view (&#8221;application/views/pages/ko3.php&#8221;) and add the following:</p>
<pre>  &lt;?php echo View::factory('blocks/ko3_inner')-&gt;render(); ?&gt;</pre>
<p>You view should like this:</p>
<pre>&lt;html&gt;
 &lt;head&gt;
  &lt;title&gt;Hello!&lt;/title&gt;
 &lt;/head&gt;
 &lt;body&gt;
  &lt;h1&gt;This is my first view&lt;/h1&gt;
  &lt;?php echo $content;?&gt;
  &lt;?php echo View::factory('blocks/ko3_inner')-&gt;render(); ?&gt;
 &lt;/body&gt;
&lt;/html&gt;</pre>
<p>So if we run it we should see what we had before, then &#8220;This is an inner view&#8221;. This would be useful for static content, but we won&#8217;t be able to use variables directly to that view. So let fix this. Lets go back to our controller (&#8221;application/classes/controllers/ko3.php&#8221;) and edit the &#8220;Action_Index&#8221; method to look like this:</p>
<pre>    public function action_index()
     {
        $ko3_inner['content']    = 'We have more data';
        $ko3['content']          = 'We have data';
        $ko3['ko3_inner']        = View::factory('blocks/ko3_inner', $ko3_inner)
                                       -&gt;render();
        $view                    = View::factory('pages/ko3', $ko3);
        $this-&gt;request-&gt;response = $view-&gt;render();
     }</pre>
<p>This will render the view to a array that then is rendered by the main view. If you noticed I did the inner stuff first and went back to using array template variable setting style. Next we will need to edit the main view (&#8221;application/views/pages/ko3.php&#8221;). The line we put in before, we will change it to:</p>
<pre>  &lt;?php echo $ko3_inner; ?&gt;</pre>
<p>The view should look like this:</p>
<pre>&lt;html&gt;
 &lt;head&gt;
  &lt;title&gt;Hello!&lt;/title&gt;
 &lt;/head&gt;
 &lt;body&gt;
  &lt;h1&gt;This is my first view&lt;/h1&gt;
  &lt;?php echo $content;?&gt;
  &lt;?php echo $ko3_inner; ?&gt;
 &lt;/body&gt;
&lt;/html&gt;</pre>
<p>And the last change we need to make is to the inner view (&#8221;application/views/blocks/ko3_inner.php&#8221;). Make it look like this:</p>
<pre>  &lt;h3&gt;This is an inner view&lt;/h3&gt;
  &lt;?php echo $content;?&gt;</pre>
<p>If you refresh the browser after saving, you should now see the following:</p>
<pre>This is my first view

We have data

This is an inner view

We have more data</pre>
<p>Pretty cool, now you can make your views more modular and reusable. Now lets get into making variables globally available to your views. Back to your controller (&#8221;applications/classes/controllers/ko3.php&#8221;) and edit the &#8220;Action_Index&#8221; method so the following is at the top of the method:</p>
<pre>       View::set_global('x', 'This is a global variable');</pre>
<p>So now the method should look like this:</p>
<pre>    public function action_index()
     {
        View::set_global('x', 'This is a global variable');

        $ko3_inner['content']    = 'We have more data';
        $ko3['content']          = 'We have data';
        $ko3['ko3_inner']        = View::factory('blocks/ko3_inner', $ko3_inner)
                                       -&gt;render();
        $view                    = View::factory('pages/ko3', $ko3);
        $this-&gt;request-&gt;response = $view-&gt;render();
     }</pre>
<p>Now if you were to edit your views and add in:</p>
<pre>  &lt;br/&gt;&lt;?php echo $x;?&gt;</pre>
<p>You should now see &#8220;This is a global variable&#8221; two times on the page. As you can see this could be very handy. Basically, we are using the static method of &#8220;set&#8221; from the view class, so it ends up being available to all view object instances. You can also use the static method of &#8220;bind&#8221; to reference variables. This could be handy for dry things &#8220;<acronym title="Don't Repeat Yourself">DRY</acronym>&#8221; and could be used in other place, like a contruct.</p>
<p>Untill next time, when I go over &#8220;templates&#8221; (advanced views and controller stuff), happy coding!<br />
Sources used: <a href="http://kerkness.ca/wiki/doku.php?id=template-site:create_the_template" target="_blank">Unofficial Kohana 3 Wiki</a></p>
<p><a href="http://images.dealtaker.com/dealtaker/blog/ko3-tutorial/mykohana3_2.zip">Get the file for this tutorial here</a></p>

<div class="sociable">
<div class="sociable_tagline">
<strong>Share and Enjoy:</strong>
</div>
<ul>
	<li class="sociablefirst"><a rel="nofollow"  target="_blank" href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fwww.dealtaker.com%2Fblog%2F2009%2F12%2F07%2Fkohana-php-3-0-ko3-tutorial-part-2%2F&amp;title=Kohana%20PHP%203.0%20%28KO3%29%20Tutorial%20Part%202&amp;bodytext=Welcome%20to%20the%20second%20part%20in%20this%20series%20on%20how%20to%20develop%20with%20Kohana%20PHP%20V3%20%28KO3%29.%20If%20you%20haven%C3%A2%E2%82%AC%E2%84%A2t%20read%20the%20first%20part%2C%20I%20would%20click%20here%20and%20read%20it%20before%20going%20on.%20In%20this%20tutorial%20we%20will%20be%20going%20over%20how%20to%20develop%20views.%0D%0A%0D%0ABefore%20we" title="Digg"><img src="http://www.dealtaker.com/blog/wp-content/plugins/sociable/images/digg.png" title="Digg" alt="Digg" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://delicious.com/post?url=http%3A%2F%2Fwww.dealtaker.com%2Fblog%2F2009%2F12%2F07%2Fkohana-php-3-0-ko3-tutorial-part-2%2F&amp;title=Kohana%20PHP%203.0%20%28KO3%29%20Tutorial%20Part%202&amp;notes=Welcome%20to%20the%20second%20part%20in%20this%20series%20on%20how%20to%20develop%20with%20Kohana%20PHP%20V3%20%28KO3%29.%20If%20you%20haven%C3%A2%E2%82%AC%E2%84%A2t%20read%20the%20first%20part%2C%20I%20would%20click%20here%20and%20read%20it%20before%20going%20on.%20In%20this%20tutorial%20we%20will%20be%20going%20over%20how%20to%20develop%20views.%0D%0A%0D%0ABefore%20we" title="del.icio.us"><img src="http://www.dealtaker.com/blog/wp-content/plugins/sociable/images/delicious.png" title="del.icio.us" alt="del.icio.us" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://www.facebook.com/share.php?u=http%3A%2F%2Fwww.dealtaker.com%2Fblog%2F2009%2F12%2F07%2Fkohana-php-3-0-ko3-tutorial-part-2%2F&amp;t=Kohana%20PHP%203.0%20%28KO3%29%20Tutorial%20Part%202" title="Facebook"><img src="http://www.dealtaker.com/blog/wp-content/plugins/sociable/images/facebook.png" title="Facebook" alt="Facebook" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://twitter.com/home?status=Kohana%20PHP%203.0%20%28KO3%29%20Tutorial%20Part%202%20-%20http%3A%2F%2Fwww.dealtaker.com%2Fblog%2F2009%2F12%2F07%2Fkohana-php-3-0-ko3-tutorial-part-2%2F" title="Twitter"><img src="http://www.dealtaker.com/blog/wp-content/plugins/sociable/images/twitter.png" title="Twitter" alt="Twitter" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fwww.dealtaker.com%2Fblog%2F2009%2F12%2F07%2Fkohana-php-3-0-ko3-tutorial-part-2%2F&amp;title=Kohana%20PHP%203.0%20%28KO3%29%20Tutorial%20Part%202" title="StumbleUpon"><img src="http://www.dealtaker.com/blog/wp-content/plugins/sociable/images/stumbleupon.png" title="StumbleUpon" alt="StumbleUpon" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://www.mixx.com/submit?page_url=http%3A%2F%2Fwww.dealtaker.com%2Fblog%2F2009%2F12%2F07%2Fkohana-php-3-0-ko3-tutorial-part-2%2F&amp;title=Kohana%20PHP%203.0%20%28KO3%29%20Tutorial%20Part%202" title="Mixx"><img src="http://www.dealtaker.com/blog/wp-content/plugins/sociable/images/mixx.png" title="Mixx" alt="Mixx" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://www.google.com/bookmarks/mark?op=edit&amp;bkmk=http%3A%2F%2Fwww.dealtaker.com%2Fblog%2F2009%2F12%2F07%2Fkohana-php-3-0-ko3-tutorial-part-2%2F&amp;title=Kohana%20PHP%203.0%20%28KO3%29%20Tutorial%20Part%202&amp;annotation=Welcome%20to%20the%20second%20part%20in%20this%20series%20on%20how%20to%20develop%20with%20Kohana%20PHP%20V3%20%28KO3%29.%20If%20you%20haven%C3%A2%E2%82%AC%E2%84%A2t%20read%20the%20first%20part%2C%20I%20would%20click%20here%20and%20read%20it%20before%20going%20on.%20In%20this%20tutorial%20we%20will%20be%20going%20over%20how%20to%20develop%20views.%0D%0A%0D%0ABefore%20we" title="Google Bookmarks"><img src="http://www.dealtaker.com/blog/wp-content/plugins/sociable/images/googlebookmark.png" title="Google Bookmarks" alt="Google Bookmarks" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://reddit.com/submit?url=http%3A%2F%2Fwww.dealtaker.com%2Fblog%2F2009%2F12%2F07%2Fkohana-php-3-0-ko3-tutorial-part-2%2F&amp;title=Kohana%20PHP%203.0%20%28KO3%29%20Tutorial%20Part%202" title="Reddit"><img src="http://www.dealtaker.com/blog/wp-content/plugins/sociable/images/reddit.png" title="Reddit" alt="Reddit" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://technorati.com/faves?add=http%3A%2F%2Fwww.dealtaker.com%2Fblog%2F2009%2F12%2F07%2Fkohana-php-3-0-ko3-tutorial-part-2%2F" title="Technorati"><img src="http://www.dealtaker.com/blog/wp-content/plugins/sociable/images/technorati.png" title="Technorati" alt="Technorati" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://buzz.yahoo.com/submit/?submitUrl=http%3A%2F%2Fwww.dealtaker.com%2Fblog%2F2009%2F12%2F07%2Fkohana-php-3-0-ko3-tutorial-part-2%2F&amp;submitHeadline=Kohana%20PHP%203.0%20%28KO3%29%20Tutorial%20Part%202&amp;submitSummary=Welcome%20to%20the%20second%20part%20in%20this%20series%20on%20how%20to%20develop%20with%20Kohana%20PHP%20V3%20%28KO3%29.%20If%20you%20haven%C3%A2%E2%82%AC%E2%84%A2t%20read%20the%20first%20part%2C%20I%20would%20click%20here%20and%20read%20it%20before%20going%20on.%20In%20this%20tutorial%20we%20will%20be%20going%20over%20how%20to%20develop%20views.%0D%0A%0D%0ABefore%20we&amp;submitCategory=science&amp;submitAssetType=text" title="Yahoo! Buzz"><img src="http://www.dealtaker.com/blog/wp-content/plugins/sociable/images/yahoobuzz.png" title="Yahoo! Buzz" alt="Yahoo! Buzz" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://www.myspace.com/Modules/PostTo/Pages/?u=http%3A%2F%2Fwww.dealtaker.com%2Fblog%2F2009%2F12%2F07%2Fkohana-php-3-0-ko3-tutorial-part-2%2F&amp;t=Kohana%20PHP%203.0%20%28KO3%29%20Tutorial%20Part%202" title="MySpace"><img src="http://www.dealtaker.com/blog/wp-content/plugins/sociable/images/myspace.png" title="MySpace" alt="MySpace" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://www.linkedin.com/shareArticle?mini=true&amp;url=http%3A%2F%2Fwww.dealtaker.com%2Fblog%2F2009%2F12%2F07%2Fkohana-php-3-0-ko3-tutorial-part-2%2F&amp;title=Kohana%20PHP%203.0%20%28KO3%29%20Tutorial%20Part%202&amp;source=Inside+DealTaker+All+Things+Deal+Oriented&amp;summary=Welcome%20to%20the%20second%20part%20in%20this%20series%20on%20how%20to%20develop%20with%20Kohana%20PHP%20V3%20%28KO3%29.%20If%20you%20haven%C3%A2%E2%82%AC%E2%84%A2t%20read%20the%20first%20part%2C%20I%20would%20click%20here%20and%20read%20it%20before%20going%20on.%20In%20this%20tutorial%20we%20will%20be%20going%20over%20how%20to%20develop%20views.%0D%0A%0D%0ABefore%20we" title="LinkedIn"><img src="http://www.dealtaker.com/blog/wp-content/plugins/sociable/images/linkedin.png" title="LinkedIn" alt="LinkedIn" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="https://favorites.live.com/quickadd.aspx?marklet=1&amp;url=http%3A%2F%2Fwww.dealtaker.com%2Fblog%2F2009%2F12%2F07%2Fkohana-php-3-0-ko3-tutorial-part-2%2F&amp;title=Kohana%20PHP%203.0%20%28KO3%29%20Tutorial%20Part%202" title="Live"><img src="http://www.dealtaker.com/blog/wp-content/plugins/sociable/images/live.png" title="Live" alt="Live" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="mailto:?subject=Kohana%20PHP%203.0%20%28KO3%29%20Tutorial%20Part%202&amp;body=http%3A%2F%2Fwww.dealtaker.com%2Fblog%2F2009%2F12%2F07%2Fkohana-php-3-0-ko3-tutorial-part-2%2F" title="email"><img src="http://www.dealtaker.com/blog/wp-content/plugins/sociable/images/email_link.png" title="email" alt="email" class="sociable-hovers" /></a></li>
	<li class="sociablelast"><a rel="nofollow"  target="_blank" href="http://www.printfriendly.com/print?url=http%3A%2F%2Fwww.dealtaker.com%2Fblog%2F2009%2F12%2F07%2Fkohana-php-3-0-ko3-tutorial-part-2%2F&amp;partner=sociable" title="Print"><img src="http://www.dealtaker.com/blog/wp-content/plugins/sociable/images/printfriendly.png" title="Print" alt="Print" class="sociable-hovers" /></a></li>
</ul>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.dealtaker.com/blog/2009/12/07/kohana-php-3-0-ko3-tutorial-part-2/feed/</wfw:commentRss>
		<slash:comments>15</slash:comments>
		</item>
		<item>
		<title>Kohana PHP 3.0 (KO3) Tutorial Part 1</title>
		<link>http://www.dealtaker.com/blog/2009/11/20/kohana-php-3-0-ko3-tutorial-part-1/</link>
		<comments>http://www.dealtaker.com/blog/2009/11/20/kohana-php-3-0-ko3-tutorial-part-1/#comments</comments>
		<pubDate>Fri, 20 Nov 2009 21:47:05 +0000</pubDate>
		<dc:creator>ellisgl</dc:creator>
				<category><![CDATA[technology]]></category>
		<category><![CDATA[controller]]></category>
		<category><![CDATA[controllers]]></category>
		<category><![CDATA[framework]]></category>
		<category><![CDATA[KO3]]></category>
		<category><![CDATA[kohana]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://www.dealtaker.com/blog/?p=1768</guid>
		<description><![CDATA[So you might have read my aricle on frameworks and/or my series of tutorials on Kohana PHP 2.3.x and you are wanting more. Today, I drop the old 2.3.x and bring the new and shiny! So I bring you information to get you started with Kohana PHP 3.0!
Lets check to make sure we have everything [...]]]></description>
			<content:encoded><![CDATA[<p>So you might have read my aricle on frameworks and/or my series of tutorials on Kohana PHP 2.3.x and you are wanting more. Today, I drop the old 2.3.x and bring the new and shiny! So I bring you information to get you started with Kohana PHP 3.0!<span id="more-1768"></span></p>
<p>Lets check to make sure we have everything needed before going on.</p>
<ul>
<li>*AMP (Apache MySQL PHP) install</li>
<li>Knowledge of PHP</li>
<li>Know what a frame work is (<a href="http://www.dealtaker.com/blog/2009/02/10/frameworks-frameworks-frameworks/">Framework Article</a>)</li>
<li>Know what MVC is (<a href="http://en.wikipedia.org/wiki/Model-view-controller">Wikipedia Entry</a>)</li>
</ul>
<p>Lets go!<br />
Download:<br />
<a href="http://dev.kohanaphp.com/projects/kohana3/files">Download the latest Kohana 3.0 PHP</a> (At the time of this writing: 3.0.1.2) and unpack it somewhere.</p>
<p>Install:<br />
Open the file we just downloaded in your favorite archive program and extract it to a temporary location. Open that temporary location and you should have a folder that is named &#8220;kohana&#8221; or something like that. Open that folder. Open a new window and open the root directory of your *AMP install. Since Iâ€™m using WAMP Server â€“ mine is &#8220;C:\wamp\www\&#8221;. Next make a new folder in there named &#8220;mykohana3&#8243;. Copy the files from the &#8220;kohana&#8221; directory to the &#8220;mykohana3&#8243;. Make sure your *AMP installation is up and running then point your browser to &#8220;http://yourserver/mykohana3/&#8221;. You should have a screen stating that everything is &#8220;OK&#8221;.<br />
<img src="//images.dealtaker.com/dealtaker/blog/ko3-tutorial/ko3-tut1-1.png" alt="" /></p>
<p>If everything is &#8220;OK&#8221;, then remove or rename the &#8220;install.php&#8221; file in the &#8220;mykohana3&#8243; directory. Next open up the &#8220;example.htaccess&#8221; file and change the following line:</p>
<pre>RewriteBase /kohana/</pre>
<p>to:<br />
<code><br />
RewriteBase /mykohana3/<br />
</code></p>
<p>Save it as &#8220;.htaccess&#8221;.</p>
<p>Now open the &#8220;bootstrap.php&#8221; file located in the &#8220;application&#8221; folder and cange the following line:</p>
<pre>Kohana::init(array('base_url' =&gt; '/kohana/'));</pre>
<p>to:</p>
<pre>Kohana::init(array('base_url'  =&gt; '/mykohana3/',
                   'index_file'=&gt; ''));</pre>
<p>Save this file then refresh your browser. You should get something that reads &#8220;hello, world!&#8221; on your screen.</p>
<p>You might already notice that configuration for KO3 is a little bit more involved, editing two files instead of one, which isn&#8217;t a big deal at all.</p>
<p>Now to make our first controller! Open a new document and put the following into it:</p>
<pre>&lt;?php
defined('SYSPATH') or die('No direct script access.');

class Controller_Ko3 extends Controller
 {
    public function action_index()
     {
        $this-&gt;request-&gt;response = 'My First Kohana 3.0 Controller';
     }
 } // End</pre>
<p>Save this as &#8220;ko3.php&#8221; in the &#8220;application/classes/controller&#8221; folder. You might have noticed another difference between Kohana 2.3.x and 3.0 is the directory structure, not really all that much of difference. Now that you have it saved, point your browser to &#8220;http://yourhost/mykohana3/ko3&#8243;. You should she &#8220;My First Kohana 3.0 Controller&#8221; on your screen now.</p>
<p>Now for an explanation of the code.</p>
<pre>defined('SYSPATH') or die('No direct script access.');</pre>
<p>This line basically tells PHP not load this file directly. It can only be included from the framework.</p>
<pre>class Controller_Ko3 extends Controller</pre>
<p>This creates an controller which is a class that is extended from the Controller class that is part of the framework.</p>
<pre>public function action_index()</pre>
<p>This created a public method called &#8220;action_index&#8221;. The &#8220;action_index&#8221; method is a default action that is loaded by the framework. It&#8217;s like your index.php file so to say.</p>
<pre>$this-&gt;request-&gt;response = 'My First Kohana 3.0 Controller';</pre>
<p>This will output &#8220;My First Kohana 3.0 Controller&#8221; to the screen. This basically works like &#8220;echo&#8221;.</p>
<p>Pretty easy eh? Now if you wanted to add addition action to your controller you would add another public method that has a prefix of &#8220;action_&#8221; and the you would access via going to &#8220;http://yourserver/mykohana3/controller/action&#8221;</p>
<p>Let go ahead and add a new method to our &#8220;ko3&#8243; controller by adding the following after the &#8220;action_index&#8221; method:</p>
<pre>    public function action_another()
     {
        $this-&gt;request-&gt;response = 'Another action';
     }</pre>
<p>Save the file and loaded up &#8220;http://yourserver/mykohana3/ko3/another&#8221; in your browser. If all goes well you should see &#8220;Another action&#8221; in your browser.</p>
<p>That was fun an all, but lets make it a little bit more dynamic!</p>
<p>Copy this code and put it after the &#8220;action_another&#8221; method:</p>
<pre>    public function action_dynamic($say)
     {
        $this-&gt;request-&gt;response = 'You said: '.$say;
     }</pre>
<p>Save this and load &#8220;http://yourserver/mykohana3/ko3/dynamic/Monkey&#8221; and you should see &#8220;You said: Monkey&#8221;</p>
<p>Untill next time, when I will go over the first part of views, happy coding!<br />
Sources used: <a href="http://kerkness.ca/wiki/doku.php">Unofficial Kohana 3 Wiki</a></p>

<div class="sociable">
<div class="sociable_tagline">
<strong>Share and Enjoy:</strong>
</div>
<ul>
	<li class="sociablefirst"><a rel="nofollow"  target="_blank" href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fwww.dealtaker.com%2Fblog%2F2009%2F11%2F20%2Fkohana-php-3-0-ko3-tutorial-part-1%2F&amp;title=Kohana%20PHP%203.0%20%28KO3%29%20Tutorial%20Part%201&amp;bodytext=So%20you%20might%20have%20read%20my%20aricle%20on%20frameworks%20and%2For%20my%20series%20of%20tutorials%20on%20Kohana%20PHP%202.3.x%20and%20you%20are%20wanting%20more.%20Today%2C%20I%20drop%20the%20old%202.3.x%20and%20bring%20the%20new%20and%20shiny%21%20So%20I%20bring%20you%20information%20to%20get%20you%20started%20with%20Kohana%20PHP%203.0%21%0D%0A%0D%0A" title="Digg"><img src="http://www.dealtaker.com/blog/wp-content/plugins/sociable/images/digg.png" title="Digg" alt="Digg" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://delicious.com/post?url=http%3A%2F%2Fwww.dealtaker.com%2Fblog%2F2009%2F11%2F20%2Fkohana-php-3-0-ko3-tutorial-part-1%2F&amp;title=Kohana%20PHP%203.0%20%28KO3%29%20Tutorial%20Part%201&amp;notes=So%20you%20might%20have%20read%20my%20aricle%20on%20frameworks%20and%2For%20my%20series%20of%20tutorials%20on%20Kohana%20PHP%202.3.x%20and%20you%20are%20wanting%20more.%20Today%2C%20I%20drop%20the%20old%202.3.x%20and%20bring%20the%20new%20and%20shiny%21%20So%20I%20bring%20you%20information%20to%20get%20you%20started%20with%20Kohana%20PHP%203.0%21%0D%0A%0D%0A" title="del.icio.us"><img src="http://www.dealtaker.com/blog/wp-content/plugins/sociable/images/delicious.png" title="del.icio.us" alt="del.icio.us" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://www.facebook.com/share.php?u=http%3A%2F%2Fwww.dealtaker.com%2Fblog%2F2009%2F11%2F20%2Fkohana-php-3-0-ko3-tutorial-part-1%2F&amp;t=Kohana%20PHP%203.0%20%28KO3%29%20Tutorial%20Part%201" title="Facebook"><img src="http://www.dealtaker.com/blog/wp-content/plugins/sociable/images/facebook.png" title="Facebook" alt="Facebook" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://twitter.com/home?status=Kohana%20PHP%203.0%20%28KO3%29%20Tutorial%20Part%201%20-%20http%3A%2F%2Fwww.dealtaker.com%2Fblog%2F2009%2F11%2F20%2Fkohana-php-3-0-ko3-tutorial-part-1%2F" title="Twitter"><img src="http://www.dealtaker.com/blog/wp-content/plugins/sociable/images/twitter.png" title="Twitter" alt="Twitter" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fwww.dealtaker.com%2Fblog%2F2009%2F11%2F20%2Fkohana-php-3-0-ko3-tutorial-part-1%2F&amp;title=Kohana%20PHP%203.0%20%28KO3%29%20Tutorial%20Part%201" title="StumbleUpon"><img src="http://www.dealtaker.com/blog/wp-content/plugins/sociable/images/stumbleupon.png" title="StumbleUpon" alt="StumbleUpon" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://www.mixx.com/submit?page_url=http%3A%2F%2Fwww.dealtaker.com%2Fblog%2F2009%2F11%2F20%2Fkohana-php-3-0-ko3-tutorial-part-1%2F&amp;title=Kohana%20PHP%203.0%20%28KO3%29%20Tutorial%20Part%201" title="Mixx"><img src="http://www.dealtaker.com/blog/wp-content/plugins/sociable/images/mixx.png" title="Mixx" alt="Mixx" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://www.google.com/bookmarks/mark?op=edit&amp;bkmk=http%3A%2F%2Fwww.dealtaker.com%2Fblog%2F2009%2F11%2F20%2Fkohana-php-3-0-ko3-tutorial-part-1%2F&amp;title=Kohana%20PHP%203.0%20%28KO3%29%20Tutorial%20Part%201&amp;annotation=So%20you%20might%20have%20read%20my%20aricle%20on%20frameworks%20and%2For%20my%20series%20of%20tutorials%20on%20Kohana%20PHP%202.3.x%20and%20you%20are%20wanting%20more.%20Today%2C%20I%20drop%20the%20old%202.3.x%20and%20bring%20the%20new%20and%20shiny%21%20So%20I%20bring%20you%20information%20to%20get%20you%20started%20with%20Kohana%20PHP%203.0%21%0D%0A%0D%0A" title="Google Bookmarks"><img src="http://www.dealtaker.com/blog/wp-content/plugins/sociable/images/googlebookmark.png" title="Google Bookmarks" alt="Google Bookmarks" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://reddit.com/submit?url=http%3A%2F%2Fwww.dealtaker.com%2Fblog%2F2009%2F11%2F20%2Fkohana-php-3-0-ko3-tutorial-part-1%2F&amp;title=Kohana%20PHP%203.0%20%28KO3%29%20Tutorial%20Part%201" title="Reddit"><img src="http://www.dealtaker.com/blog/wp-content/plugins/sociable/images/reddit.png" title="Reddit" alt="Reddit" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://technorati.com/faves?add=http%3A%2F%2Fwww.dealtaker.com%2Fblog%2F2009%2F11%2F20%2Fkohana-php-3-0-ko3-tutorial-part-1%2F" title="Technorati"><img src="http://www.dealtaker.com/blog/wp-content/plugins/sociable/images/technorati.png" title="Technorati" alt="Technorati" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://buzz.yahoo.com/submit/?submitUrl=http%3A%2F%2Fwww.dealtaker.com%2Fblog%2F2009%2F11%2F20%2Fkohana-php-3-0-ko3-tutorial-part-1%2F&amp;submitHeadline=Kohana%20PHP%203.0%20%28KO3%29%20Tutorial%20Part%201&amp;submitSummary=So%20you%20might%20have%20read%20my%20aricle%20on%20frameworks%20and%2For%20my%20series%20of%20tutorials%20on%20Kohana%20PHP%202.3.x%20and%20you%20are%20wanting%20more.%20Today%2C%20I%20drop%20the%20old%202.3.x%20and%20bring%20the%20new%20and%20shiny%21%20So%20I%20bring%20you%20information%20to%20get%20you%20started%20with%20Kohana%20PHP%203.0%21%0D%0A%0D%0A&amp;submitCategory=science&amp;submitAssetType=text" title="Yahoo! Buzz"><img src="http://www.dealtaker.com/blog/wp-content/plugins/sociable/images/yahoobuzz.png" title="Yahoo! Buzz" alt="Yahoo! Buzz" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://www.myspace.com/Modules/PostTo/Pages/?u=http%3A%2F%2Fwww.dealtaker.com%2Fblog%2F2009%2F11%2F20%2Fkohana-php-3-0-ko3-tutorial-part-1%2F&amp;t=Kohana%20PHP%203.0%20%28KO3%29%20Tutorial%20Part%201" title="MySpace"><img src="http://www.dealtaker.com/blog/wp-content/plugins/sociable/images/myspace.png" title="MySpace" alt="MySpace" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://www.linkedin.com/shareArticle?mini=true&amp;url=http%3A%2F%2Fwww.dealtaker.com%2Fblog%2F2009%2F11%2F20%2Fkohana-php-3-0-ko3-tutorial-part-1%2F&amp;title=Kohana%20PHP%203.0%20%28KO3%29%20Tutorial%20Part%201&amp;source=Inside+DealTaker+All+Things+Deal+Oriented&amp;summary=So%20you%20might%20have%20read%20my%20aricle%20on%20frameworks%20and%2For%20my%20series%20of%20tutorials%20on%20Kohana%20PHP%202.3.x%20and%20you%20are%20wanting%20more.%20Today%2C%20I%20drop%20the%20old%202.3.x%20and%20bring%20the%20new%20and%20shiny%21%20So%20I%20bring%20you%20information%20to%20get%20you%20started%20with%20Kohana%20PHP%203.0%21%0D%0A%0D%0A" title="LinkedIn"><img src="http://www.dealtaker.com/blog/wp-content/plugins/sociable/images/linkedin.png" title="LinkedIn" alt="LinkedIn" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="https://favorites.live.com/quickadd.aspx?marklet=1&amp;url=http%3A%2F%2Fwww.dealtaker.com%2Fblog%2F2009%2F11%2F20%2Fkohana-php-3-0-ko3-tutorial-part-1%2F&amp;title=Kohana%20PHP%203.0%20%28KO3%29%20Tutorial%20Part%201" title="Live"><img src="http://www.dealtaker.com/blog/wp-content/plugins/sociable/images/live.png" title="Live" alt="Live" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="mailto:?subject=Kohana%20PHP%203.0%20%28KO3%29%20Tutorial%20Part%201&amp;body=http%3A%2F%2Fwww.dealtaker.com%2Fblog%2F2009%2F11%2F20%2Fkohana-php-3-0-ko3-tutorial-part-1%2F" title="email"><img src="http://www.dealtaker.com/blog/wp-content/plugins/sociable/images/email_link.png" title="email" alt="email" class="sociable-hovers" /></a></li>
	<li class="sociablelast"><a rel="nofollow"  target="_blank" href="http://www.printfriendly.com/print?url=http%3A%2F%2Fwww.dealtaker.com%2Fblog%2F2009%2F11%2F20%2Fkohana-php-3-0-ko3-tutorial-part-1%2F&amp;partner=sociable" title="Print"><img src="http://www.dealtaker.com/blog/wp-content/plugins/sociable/images/printfriendly.png" title="Print" alt="Print" class="sociable-hovers" /></a></li>
</ul>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.dealtaker.com/blog/2009/11/20/kohana-php-3-0-ko3-tutorial-part-1/feed/</wfw:commentRss>
		<slash:comments>19</slash:comments>
		</item>
		<item>
		<title>DealTaker Did You Know &#8211; Vol 1. Coupon Alerts</title>
		<link>http://www.dealtaker.com/blog/2009/07/27/dealtaker-did-you-know-vol-1-coupon-alerts/</link>
		<comments>http://www.dealtaker.com/blog/2009/07/27/dealtaker-did-you-know-vol-1-coupon-alerts/#comments</comments>
		<pubDate>Mon, 27 Jul 2009 21:14:53 +0000</pubDate>
		<dc:creator>DBiles</dc:creator>
				<category><![CDATA[DealTaker]]></category>
		<category><![CDATA[Product Discussion]]></category>
		<category><![CDATA[technology]]></category>
		<category><![CDATA[Coupon Alerts]]></category>
		<category><![CDATA[Coupon Email Alerts]]></category>

		<guid isPermaLink="false">http://www.dealtaker.com/blog/?p=1235</guid>
		<description><![CDATA[From time to time, I&#8217;ll be writing on this blog about some features you may not have known existed on DealTaker. Today: Did you know that you can be alerted by email anytime new coupons are posted for your favorite store?
It&#8217;s easy. First, go to DealTaker.com and then click the &#8220;Stores/Coupons&#8221; button in the top [...]]]></description>
			<content:encoded><![CDATA[<p>From time to time, I&#8217;ll be writing on this blog about some features you may not have known existed on DealTaker. Today: Did you know that you can be alerted by email anytime new coupons are posted for your favorite store?</p>
<p>It&#8217;s easy. First, go to DealTaker.com and then click the &#8220;Stores/Coupons&#8221; button in the top navigation bar.</p>
<p><img class="alignleft size-full wp-image-1236" title="storescouponsnav" src="http://www.dealtaker.com/blog/wp-content/uploads/2009/07/storescouponsnav.jpg" alt="storescouponsnav" width="340" height="171" /></p>
<p>Then select the store that you want to get alerts from. For this example, we&#8217;ll use Kohl&#8217;s.</p>
<p><img class="alignleft size-full wp-image-1237" title="kohlsselect" src="http://www.dealtaker.com/blog/wp-content/uploads/2009/07/kohlsselect.jpg" alt="kohlsselect" width="474" height="186" /></p>
<p>Once there, you&#8217;ll see a list of coupons for the store. The last coupon allows you to sign up to be alerted when new coupons are posted. If you are already a member of DealTaker (and logged in!) all you&#8217;ll have to do is click the &#8220;Sign me up!&#8221; button and they will be delivered to the email address that you originally signed up to DealTaker with.</p>
<p>If you are not a member of DealTaker, just enter your email address into the box and new coupons will be delivered straight to your inbox!</p>

<div class="sociable">
<div class="sociable_tagline">
<strong>Share and Enjoy:</strong>
</div>
<ul>
	<li class="sociablefirst"><a rel="nofollow"  target="_blank" href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fwww.dealtaker.com%2Fblog%2F2009%2F07%2F27%2Fdealtaker-did-you-know-vol-1-coupon-alerts%2F&amp;title=DealTaker%20Did%20You%20Know%20-%20Vol%201.%20Coupon%20Alerts&amp;bodytext=From%20time%20to%20time%2C%20I%27ll%20be%20writing%20on%20this%20blog%20about%20some%20features%20you%20may%20not%20have%20known%20existed%20on%20DealTaker.%20Today%3A%20Did%20you%20know%20that%20you%20can%20be%20alerted%20by%20email%20anytime%20new%20coupons%20are%20posted%20for%20your%20favorite%20store%3F%0D%0A%0D%0AIt%27s%20easy.%20First%2C%20go%20to%20D" title="Digg"><img src="http://www.dealtaker.com/blog/wp-content/plugins/sociable/images/digg.png" title="Digg" alt="Digg" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://delicious.com/post?url=http%3A%2F%2Fwww.dealtaker.com%2Fblog%2F2009%2F07%2F27%2Fdealtaker-did-you-know-vol-1-coupon-alerts%2F&amp;title=DealTaker%20Did%20You%20Know%20-%20Vol%201.%20Coupon%20Alerts&amp;notes=From%20time%20to%20time%2C%20I%27ll%20be%20writing%20on%20this%20blog%20about%20some%20features%20you%20may%20not%20have%20known%20existed%20on%20DealTaker.%20Today%3A%20Did%20you%20know%20that%20you%20can%20be%20alerted%20by%20email%20anytime%20new%20coupons%20are%20posted%20for%20your%20favorite%20store%3F%0D%0A%0D%0AIt%27s%20easy.%20First%2C%20go%20to%20D" title="del.icio.us"><img src="http://www.dealtaker.com/blog/wp-content/plugins/sociable/images/delicious.png" title="del.icio.us" alt="del.icio.us" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://www.facebook.com/share.php?u=http%3A%2F%2Fwww.dealtaker.com%2Fblog%2F2009%2F07%2F27%2Fdealtaker-did-you-know-vol-1-coupon-alerts%2F&amp;t=DealTaker%20Did%20You%20Know%20-%20Vol%201.%20Coupon%20Alerts" title="Facebook"><img src="http://www.dealtaker.com/blog/wp-content/plugins/sociable/images/facebook.png" title="Facebook" alt="Facebook" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://twitter.com/home?status=DealTaker%20Did%20You%20Know%20-%20Vol%201.%20Coupon%20Alerts%20-%20http%3A%2F%2Fwww.dealtaker.com%2Fblog%2F2009%2F07%2F27%2Fdealtaker-did-you-know-vol-1-coupon-alerts%2F" title="Twitter"><img src="http://www.dealtaker.com/blog/wp-content/plugins/sociable/images/twitter.png" title="Twitter" alt="Twitter" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fwww.dealtaker.com%2Fblog%2F2009%2F07%2F27%2Fdealtaker-did-you-know-vol-1-coupon-alerts%2F&amp;title=DealTaker%20Did%20You%20Know%20-%20Vol%201.%20Coupon%20Alerts" title="StumbleUpon"><img src="http://www.dealtaker.com/blog/wp-content/plugins/sociable/images/stumbleupon.png" title="StumbleUpon" alt="StumbleUpon" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://www.mixx.com/submit?page_url=http%3A%2F%2Fwww.dealtaker.com%2Fblog%2F2009%2F07%2F27%2Fdealtaker-did-you-know-vol-1-coupon-alerts%2F&amp;title=DealTaker%20Did%20You%20Know%20-%20Vol%201.%20Coupon%20Alerts" title="Mixx"><img src="http://www.dealtaker.com/blog/wp-content/plugins/sociable/images/mixx.png" title="Mixx" alt="Mixx" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://www.google.com/bookmarks/mark?op=edit&amp;bkmk=http%3A%2F%2Fwww.dealtaker.com%2Fblog%2F2009%2F07%2F27%2Fdealtaker-did-you-know-vol-1-coupon-alerts%2F&amp;title=DealTaker%20Did%20You%20Know%20-%20Vol%201.%20Coupon%20Alerts&amp;annotation=From%20time%20to%20time%2C%20I%27ll%20be%20writing%20on%20this%20blog%20about%20some%20features%20you%20may%20not%20have%20known%20existed%20on%20DealTaker.%20Today%3A%20Did%20you%20know%20that%20you%20can%20be%20alerted%20by%20email%20anytime%20new%20coupons%20are%20posted%20for%20your%20favorite%20store%3F%0D%0A%0D%0AIt%27s%20easy.%20First%2C%20go%20to%20D" title="Google Bookmarks"><img src="http://www.dealtaker.com/blog/wp-content/plugins/sociable/images/googlebookmark.png" title="Google Bookmarks" alt="Google Bookmarks" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://reddit.com/submit?url=http%3A%2F%2Fwww.dealtaker.com%2Fblog%2F2009%2F07%2F27%2Fdealtaker-did-you-know-vol-1-coupon-alerts%2F&amp;title=DealTaker%20Did%20You%20Know%20-%20Vol%201.%20Coupon%20Alerts" title="Reddit"><img src="http://www.dealtaker.com/blog/wp-content/plugins/sociable/images/reddit.png" title="Reddit" alt="Reddit" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://technorati.com/faves?add=http%3A%2F%2Fwww.dealtaker.com%2Fblog%2F2009%2F07%2F27%2Fdealtaker-did-you-know-vol-1-coupon-alerts%2F" title="Technorati"><img src="http://www.dealtaker.com/blog/wp-content/plugins/sociable/images/technorati.png" title="Technorati" alt="Technorati" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://buzz.yahoo.com/submit/?submitUrl=http%3A%2F%2Fwww.dealtaker.com%2Fblog%2F2009%2F07%2F27%2Fdealtaker-did-you-know-vol-1-coupon-alerts%2F&amp;submitHeadline=DealTaker%20Did%20You%20Know%20-%20Vol%201.%20Coupon%20Alerts&amp;submitSummary=From%20time%20to%20time%2C%20I%27ll%20be%20writing%20on%20this%20blog%20about%20some%20features%20you%20may%20not%20have%20known%20existed%20on%20DealTaker.%20Today%3A%20Did%20you%20know%20that%20you%20can%20be%20alerted%20by%20email%20anytime%20new%20coupons%20are%20posted%20for%20your%20favorite%20store%3F%0D%0A%0D%0AIt%27s%20easy.%20First%2C%20go%20to%20D&amp;submitCategory=science&amp;submitAssetType=text" title="Yahoo! Buzz"><img src="http://www.dealtaker.com/blog/wp-content/plugins/sociable/images/yahoobuzz.png" title="Yahoo! Buzz" alt="Yahoo! Buzz" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://www.myspace.com/Modules/PostTo/Pages/?u=http%3A%2F%2Fwww.dealtaker.com%2Fblog%2F2009%2F07%2F27%2Fdealtaker-did-you-know-vol-1-coupon-alerts%2F&amp;t=DealTaker%20Did%20You%20Know%20-%20Vol%201.%20Coupon%20Alerts" title="MySpace"><img src="http://www.dealtaker.com/blog/wp-content/plugins/sociable/images/myspace.png" title="MySpace" alt="MySpace" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://www.linkedin.com/shareArticle?mini=true&amp;url=http%3A%2F%2Fwww.dealtaker.com%2Fblog%2F2009%2F07%2F27%2Fdealtaker-did-you-know-vol-1-coupon-alerts%2F&amp;title=DealTaker%20Did%20You%20Know%20-%20Vol%201.%20Coupon%20Alerts&amp;source=Inside+DealTaker+All+Things+Deal+Oriented&amp;summary=From%20time%20to%20time%2C%20I%27ll%20be%20writing%20on%20this%20blog%20about%20some%20features%20you%20may%20not%20have%20known%20existed%20on%20DealTaker.%20Today%3A%20Did%20you%20know%20that%20you%20can%20be%20alerted%20by%20email%20anytime%20new%20coupons%20are%20posted%20for%20your%20favorite%20store%3F%0D%0A%0D%0AIt%27s%20easy.%20First%2C%20go%20to%20D" title="LinkedIn"><img src="http://www.dealtaker.com/blog/wp-content/plugins/sociable/images/linkedin.png" title="LinkedIn" alt="LinkedIn" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="https://favorites.live.com/quickadd.aspx?marklet=1&amp;url=http%3A%2F%2Fwww.dealtaker.com%2Fblog%2F2009%2F07%2F27%2Fdealtaker-did-you-know-vol-1-coupon-alerts%2F&amp;title=DealTaker%20Did%20You%20Know%20-%20Vol%201.%20Coupon%20Alerts" title="Live"><img src="http://www.dealtaker.com/blog/wp-content/plugins/sociable/images/live.png" title="Live" alt="Live" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="mailto:?subject=DealTaker%20Did%20You%20Know%20-%20Vol%201.%20Coupon%20Alerts&amp;body=http%3A%2F%2Fwww.dealtaker.com%2Fblog%2F2009%2F07%2F27%2Fdealtaker-did-you-know-vol-1-coupon-alerts%2F" title="email"><img src="http://www.dealtaker.com/blog/wp-content/plugins/sociable/images/email_link.png" title="email" alt="email" class="sociable-hovers" /></a></li>
	<li class="sociablelast"><a rel="nofollow"  target="_blank" href="http://www.printfriendly.com/print?url=http%3A%2F%2Fwww.dealtaker.com%2Fblog%2F2009%2F07%2F27%2Fdealtaker-did-you-know-vol-1-coupon-alerts%2F&amp;partner=sociable" title="Print"><img src="http://www.dealtaker.com/blog/wp-content/plugins/sociable/images/printfriendly.png" title="Print" alt="Print" class="sociable-hovers" /></a></li>
</ul>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.dealtaker.com/blog/2009/07/27/dealtaker-did-you-know-vol-1-coupon-alerts/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Kohana PHP Tuturial &#8211; Part III</title>
		<link>http://www.dealtaker.com/blog/2009/06/19/kohana-php-tuturial-part-iii/</link>
		<comments>http://www.dealtaker.com/blog/2009/06/19/kohana-php-tuturial-part-iii/#comments</comments>
		<pubDate>Fri, 19 Jun 2009 13:26:09 +0000</pubDate>
		<dc:creator>ellisgl</dc:creator>
				<category><![CDATA[technology]]></category>
		<category><![CDATA[db]]></category>
		<category><![CDATA[framework]]></category>
		<category><![CDATA[howto]]></category>
		<category><![CDATA[kohana]]></category>
		<category><![CDATA[models]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://www.dealtaker.com/blog/?p=1013</guid>
		<description><![CDATA[It&#8217;s been a couple weeks now, so lets get back on track with this series of tutorials. This tutorial will get into models and how to play with data.

The first thing I have to is tell you is that Kohana PHP has been updated since the last tutorial. So I have gone ahead and took [...]]]></description>
			<content:encoded><![CDATA[<p>It&#8217;s been a couple weeks now, so lets get back on track with this series of tutorials. This tutorial will get into models and how to play with data.<br />
<span id="more-1013"></span></p>
<p>The first thing I have to is tell you is that Kohana PHP has been updated since the last tutorial. So I have gone ahead and took the last tutorial and updated the core and made sure it worked with Kohana 2.3.4. <a href="http://images.dealtaker.com/dealtaker/blog/kohana/dealtaker-kohana-2-2.3.4.zip">You can grab that here</a>. Now onward to the glory!</p>
<p>The first thing we want to do is identify where and what the data is. Is it an XML feed, CSV, JSON, DB or something else? Well I&#8217;m going to make it easy. We are going to deal with our friend MySQL for this. The next step is to setup a MySQL DB connection.</p>
<p>Go into your system/config folder and copy the database.php file to your application/config folder. Edit the application/config/database.php to reflect your server settings. Mine looks like this:</p>
<pre style="white-space: -moz-pre-wrap;white-space: -pre-wrap;white-space: -o-pre-wrap;word-wrap: break-word;">$config['default'] = array
(
	'benchmark'     =&gt; TRUE,
	'persistent'    =&gt; FALSE,
	'connection'    =&gt; array
	(
		'type'     =&gt; 'mysql',
		'user'     =&gt; 'root',
		'pass'     =&gt; 'root',
		'host'     =&gt; 'localhost',
		'port'     =&gt; FALSE,
		'socket'   =&gt; FALSE,
		'database' =&gt; 'myfirstkohana'
	),
	'character_set' =&gt; 'utf8',
	'table_prefix'  =&gt; '',
	'object'        =&gt; TRUE,
	'cache'         =&gt; FALSE,
	'escape'        =&gt; TRUE
);</pre>
<p>Now that we have a configuration a connection for our database, we should probably set up a database and a table. Here&#8217;s the SQL:</p>
<pre style="white-space: -moz-pre-wrap;white-space: -pre-wrap;white-space: -o-pre-wrap;word-wrap: break-word;">/*!40101 SET NAMES utf8 */;
/*!40101 SET SQL_MODE=''*/;
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
CREATE DATABASE /*!32312 IF NOT EXISTS*/`myfirstkohana` /*!40100 DEFAULT CHARACTER SET utf8 */;

USE `myfirstkohana`;

/*Table structure for table `posts` */
DROP TABLE IF EXISTS `posts`;

CREATE TABLE `posts` (
  `id` mediumint(8) unsigned NOT NULL auto_increment,
  `title` varchar(255) default NULL,
  `post` text,
  PRIMARY KEY  (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 CHECKSUM=1 DELAY_KEY_WRITE=1 ROW_FORMAT=DYNAMIC;

/*Data for the table `posts` */
/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;</pre>
<p>This is a pretty straight forward &#8220;Create a DB and one table&#8221; setup. You might notice that we have everything set for UTF8. This will match the DB configuration setting and also will allow us to deal with i18n (Internationalization) stuff later on.</p>
<p>Onward to creating an actual model. There are a couple things to keep in mind with naming conventions, well really one. From the docs &#8220;The model class name is capitalized, does have _Model appended to it and should be the singular form of the name.&#8221;. There are so other rules when you are dealing with ORM, but we won&#8217;t be dealing with ORM in this tutorial.</p>
<p>Create a file named post.php in the &#8216;application/models/&#8217; folder and make it look like the following:</p>
<pre style="white-space: -moz-pre-wrap;white-space: -pre-wrap;white-space: -o-pre-wrap;word-wrap: break-word;">&lt;?php
defined('SYSPATH') or die('No direct script access.');

class Post_Model extends Model
 {
    public function __construct()
    	{
		      parent::__construct();
    	}

 }</pre>
<p>As you can tell the above really doesn&#8217;t do much, so let&#8217;s give it some functionality:</p>
<pre style="white-space: -moz-pre-wrap;white-space: -pre-wrap;white-space: -o-pre-wrap;word-wrap: break-word;">&lt;?php
defined('SYSPATH') or die('No direct script access.');

class Post_Model extends Model
 {
    public function __construct()
    	{
		      parent::__construct();
    	}

    public function getPosts()
     {
        $sql = 'SELECT *
                FROM   `posts`
                LIMIT  0, 10';

        return $this-&gt;db-&gt;query($sql);
     }
 }</pre>
<p>So we have a model method that pulls 10 posts from the table with a pretty simple query. We use &#8220;$this-&gt;query()&#8221; to run queries, which will return object and we return that to the calling entity. Check the query method <a href="http://docs.kohanaphp.com/libraries/database/query" target="_blank">docs here</a> for more information.</p>
<p>Let&#8217;s update our &#8216;Hello&#8217; controller to use this the model.</p>
<p>In your application/controllers/hello.php update your index() method to look like this:</p>
<pre>    public function index()
     {
        // Load the models
        $post  = new Post_Model;
        $posts = $post-&gt;getPosts();
        $rpsts = "";

        // Loop thru the posts
        foreach($posts-&gt;result_array(FALSE) as $row)
         {
          // Simple output of
          $rpsts .= '
    &lt;h1&gt;'.$row['title'].'&lt;/h1&gt;
    '.$row['post'].'&lt;hr /&gt;';
         }

        // Put something useful in our variables.
        $this-&gt;template-&gt;header-&gt;pageTitle .= ' ::: I am on the top';
        $this-&gt;template-&gt;content-&gt;content   = $rpsts;
     }</pre>
<p>When we run the hello controller, we won&#8217;t get much but &#8216;This is my second view&#8217;. We need to put stuff in the table. Use your favorite method of accessing your DB and insert some rows. Now when you run it you will see stuff!</p>
<p>If you notice there is a &#8220;$post-&gt;result_array()&#8221; inside a foreach loop. This allows us to loop though the results of the query easily from within the controller.</p>
<p>You might have notice something of bad practice. I pretty much created HTML inside the controller. As we all know, we shouldn&#8217;t do this. Let&#8217;s fix this!</p>
<p>Create a new view named main_posts.php and make it look like:</p>
<pre style="white-space: -moz-pre-wrap;white-space: -pre-wrap;white-space: -o-pre-wrap;word-wrap: break-word;">&lt;?php foreach($posts as $post): ?&gt;
&lt;h1&gt;&lt;?php echo $post['title'];?&gt;&lt;h1&gt;
&lt;?php echo $post['post'];?&gt;&lt;hr /&gt;
&lt;?php endforeach; ?&gt;</pre>
<p>This view does a foreach on our query results and fills in our little view.</p>
<p>In the the index method of our controller we will need to change up the controller to use our new view.</p>
<pre style="white-space: -moz-pre-wrap;white-space: -pre-wrap;white-space: -o-pre-wrap;word-wrap: break-word;">   public function index()
     {
        // Load the models
        $post  = new Post_Model;
        $posts = $post-&gt;getPosts();

        // Put something useful in our variables.
        $this-&gt;template-&gt;header-&gt;pageTitle .= ' ::: I am on the top';

        // Posts view
        $this-&gt;template-&gt;content-&gt;content        = new View('main_posts');
        $this-&gt;template-&gt;content-&gt;content-&gt;posts = $posts-&gt;result_array(FALSE);
     }</pre>
<p>As you can tell, it&#8217;s pretty simple and it&#8217;s clean! Here&#8217;s a quick sample on how to do an insert. We are going to add a method to the post model called addPost.</p>
<pre style="white-space: -moz-pre-wrap;white-space: -pre-wrap;white-space: -o-pre-wrap;word-wrap: break-word;">  public function addPost($title, $post)
    {
       $sql = sprintf('INSERT INTO `posts`
                       SET         `title` = %s,
                                   `post`  = %s',
                       $this-&gt;db-&gt;escape($title),
                       $this-&gt;db-&gt;escape($post));
      $this-&gt;db-&gt;query($sql);
    }</pre>
<p>We need to add a method to handle adding of posts to our hello controller:</p>
<pre style="white-space: -moz-pre-wrap;white-space: -pre-wrap;white-space: -o-pre-wrap;word-wrap: break-word;">   public function addpost()
     {
        // Load the models
        $post  = new Post_Model;
        $post-&gt;addPost($_POST['title'], $_POST['post']);
        url::redirect('hello');
     }</pre>
<p>And lets add a form to the end of the main_post.php in the views:</p>
<pre style="white-space: -moz-pre-wrap;white-space: -pre-wrap;white-space: -o-pre-wrap;word-wrap: break-word;">&lt;form method="POST" action="&lt;?php echo url::base();?&gt;hello/addpost/"&gt;
  &lt;table&gt;
    &lt;tr&gt;
     &lt;th&gt;
       Title
     &lt;/th&gt;
     &lt;th&gt;
       Post
     &lt;/th&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
     &lt;td&gt;
      &lt;input type="text" name="title" /&gt;
     &lt;/td&gt;
     &lt;td&gt;
      &lt;textarea cols="20" rows="5" name="post"&gt;&lt;/textarea&gt;
      &lt;input type="submit" name="submit" value="Submit"/&gt;
     &lt;/td&gt;
  &lt;/table&gt;
&lt;/form&gt;</pre>
<p>Once again, pretty simple right? I could go on and give you how to edit entries, but I&#8217;m leaving that to you for your home work. Free free to post your results! Until next time when will go over libraries and helpers, keep on coding till your fingers bleed!</p>
<p><a href="http://images.dealtaker.com/dealtaker/blog/kohana/dealtaker-kohana-3.zip">Get the file for this tutorial here.</a></p>

<div class="sociable">
<div class="sociable_tagline">
<strong>Share and Enjoy:</strong>
</div>
<ul>
	<li class="sociablefirst"><a rel="nofollow"  target="_blank" href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fwww.dealtaker.com%2Fblog%2F2009%2F06%2F19%2Fkohana-php-tuturial-part-iii%2F&amp;title=Kohana%20PHP%20Tuturial%20-%20Part%20III&amp;bodytext=It%27s%20been%20a%20couple%20weeks%20now%2C%20so%20lets%20get%20back%20on%20track%20with%20this%20series%20of%20tutorials.%20This%20tutorial%20will%20get%20into%20models%20and%20how%20to%20play%20with%20data.%0D%0A%0D%0A%0D%0AThe%20first%20thing%20I%20have%20to%20is%20tell%20you%20is%20that%20Kohana%20PHP%20has%20been%20updated%20since%20the%20last%20tutoria" title="Digg"><img src="http://www.dealtaker.com/blog/wp-content/plugins/sociable/images/digg.png" title="Digg" alt="Digg" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://delicious.com/post?url=http%3A%2F%2Fwww.dealtaker.com%2Fblog%2F2009%2F06%2F19%2Fkohana-php-tuturial-part-iii%2F&amp;title=Kohana%20PHP%20Tuturial%20-%20Part%20III&amp;notes=It%27s%20been%20a%20couple%20weeks%20now%2C%20so%20lets%20get%20back%20on%20track%20with%20this%20series%20of%20tutorials.%20This%20tutorial%20will%20get%20into%20models%20and%20how%20to%20play%20with%20data.%0D%0A%0D%0A%0D%0AThe%20first%20thing%20I%20have%20to%20is%20tell%20you%20is%20that%20Kohana%20PHP%20has%20been%20updated%20since%20the%20last%20tutoria" title="del.icio.us"><img src="http://www.dealtaker.com/blog/wp-content/plugins/sociable/images/delicious.png" title="del.icio.us" alt="del.icio.us" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://www.facebook.com/share.php?u=http%3A%2F%2Fwww.dealtaker.com%2Fblog%2F2009%2F06%2F19%2Fkohana-php-tuturial-part-iii%2F&amp;t=Kohana%20PHP%20Tuturial%20-%20Part%20III" title="Facebook"><img src="http://www.dealtaker.com/blog/wp-content/plugins/sociable/images/facebook.png" title="Facebook" alt="Facebook" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://twitter.com/home?status=Kohana%20PHP%20Tuturial%20-%20Part%20III%20-%20http%3A%2F%2Fwww.dealtaker.com%2Fblog%2F2009%2F06%2F19%2Fkohana-php-tuturial-part-iii%2F" title="Twitter"><img src="http://www.dealtaker.com/blog/wp-content/plugins/sociable/images/twitter.png" title="Twitter" alt="Twitter" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fwww.dealtaker.com%2Fblog%2F2009%2F06%2F19%2Fkohana-php-tuturial-part-iii%2F&amp;title=Kohana%20PHP%20Tuturial%20-%20Part%20III" title="StumbleUpon"><img src="http://www.dealtaker.com/blog/wp-content/plugins/sociable/images/stumbleupon.png" title="StumbleUpon" alt="StumbleUpon" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://www.mixx.com/submit?page_url=http%3A%2F%2Fwww.dealtaker.com%2Fblog%2F2009%2F06%2F19%2Fkohana-php-tuturial-part-iii%2F&amp;title=Kohana%20PHP%20Tuturial%20-%20Part%20III" title="Mixx"><img src="http://www.dealtaker.com/blog/wp-content/plugins/sociable/images/mixx.png" title="Mixx" alt="Mixx" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://www.google.com/bookmarks/mark?op=edit&amp;bkmk=http%3A%2F%2Fwww.dealtaker.com%2Fblog%2F2009%2F06%2F19%2Fkohana-php-tuturial-part-iii%2F&amp;title=Kohana%20PHP%20Tuturial%20-%20Part%20III&amp;annotation=It%27s%20been%20a%20couple%20weeks%20now%2C%20so%20lets%20get%20back%20on%20track%20with%20this%20series%20of%20tutorials.%20This%20tutorial%20will%20get%20into%20models%20and%20how%20to%20play%20with%20data.%0D%0A%0D%0A%0D%0AThe%20first%20thing%20I%20have%20to%20is%20tell%20you%20is%20that%20Kohana%20PHP%20has%20been%20updated%20since%20the%20last%20tutoria" title="Google Bookmarks"><img src="http://www.dealtaker.com/blog/wp-content/plugins/sociable/images/googlebookmark.png" title="Google Bookmarks" alt="Google Bookmarks" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://reddit.com/submit?url=http%3A%2F%2Fwww.dealtaker.com%2Fblog%2F2009%2F06%2F19%2Fkohana-php-tuturial-part-iii%2F&amp;title=Kohana%20PHP%20Tuturial%20-%20Part%20III" title="Reddit"><img src="http://www.dealtaker.com/blog/wp-content/plugins/sociable/images/reddit.png" title="Reddit" alt="Reddit" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://technorati.com/faves?add=http%3A%2F%2Fwww.dealtaker.com%2Fblog%2F2009%2F06%2F19%2Fkohana-php-tuturial-part-iii%2F" title="Technorati"><img src="http://www.dealtaker.com/blog/wp-content/plugins/sociable/images/technorati.png" title="Technorati" alt="Technorati" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://buzz.yahoo.com/submit/?submitUrl=http%3A%2F%2Fwww.dealtaker.com%2Fblog%2F2009%2F06%2F19%2Fkohana-php-tuturial-part-iii%2F&amp;submitHeadline=Kohana%20PHP%20Tuturial%20-%20Part%20III&amp;submitSummary=It%27s%20been%20a%20couple%20weeks%20now%2C%20so%20lets%20get%20back%20on%20track%20with%20this%20series%20of%20tutorials.%20This%20tutorial%20will%20get%20into%20models%20and%20how%20to%20play%20with%20data.%0D%0A%0D%0A%0D%0AThe%20first%20thing%20I%20have%20to%20is%20tell%20you%20is%20that%20Kohana%20PHP%20has%20been%20updated%20since%20the%20last%20tutoria&amp;submitCategory=science&amp;submitAssetType=text" title="Yahoo! Buzz"><img src="http://www.dealtaker.com/blog/wp-content/plugins/sociable/images/yahoobuzz.png" title="Yahoo! Buzz" alt="Yahoo! Buzz" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://www.myspace.com/Modules/PostTo/Pages/?u=http%3A%2F%2Fwww.dealtaker.com%2Fblog%2F2009%2F06%2F19%2Fkohana-php-tuturial-part-iii%2F&amp;t=Kohana%20PHP%20Tuturial%20-%20Part%20III" title="MySpace"><img src="http://www.dealtaker.com/blog/wp-content/plugins/sociable/images/myspace.png" title="MySpace" alt="MySpace" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://www.linkedin.com/shareArticle?mini=true&amp;url=http%3A%2F%2Fwww.dealtaker.com%2Fblog%2F2009%2F06%2F19%2Fkohana-php-tuturial-part-iii%2F&amp;title=Kohana%20PHP%20Tuturial%20-%20Part%20III&amp;source=Inside+DealTaker+All+Things+Deal+Oriented&amp;summary=It%27s%20been%20a%20couple%20weeks%20now%2C%20so%20lets%20get%20back%20on%20track%20with%20this%20series%20of%20tutorials.%20This%20tutorial%20will%20get%20into%20models%20and%20how%20to%20play%20with%20data.%0D%0A%0D%0A%0D%0AThe%20first%20thing%20I%20have%20to%20is%20tell%20you%20is%20that%20Kohana%20PHP%20has%20been%20updated%20since%20the%20last%20tutoria" title="LinkedIn"><img src="http://www.dealtaker.com/blog/wp-content/plugins/sociable/images/linkedin.png" title="LinkedIn" alt="LinkedIn" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="https://favorites.live.com/quickadd.aspx?marklet=1&amp;url=http%3A%2F%2Fwww.dealtaker.com%2Fblog%2F2009%2F06%2F19%2Fkohana-php-tuturial-part-iii%2F&amp;title=Kohana%20PHP%20Tuturial%20-%20Part%20III" title="Live"><img src="http://www.dealtaker.com/blog/wp-content/plugins/sociable/images/live.png" title="Live" alt="Live" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="mailto:?subject=Kohana%20PHP%20Tuturial%20-%20Part%20III&amp;body=http%3A%2F%2Fwww.dealtaker.com%2Fblog%2F2009%2F06%2F19%2Fkohana-php-tuturial-part-iii%2F" title="email"><img src="http://www.dealtaker.com/blog/wp-content/plugins/sociable/images/email_link.png" title="email" alt="email" class="sociable-hovers" /></a></li>
	<li class="sociablelast"><a rel="nofollow"  target="_blank" href="http://www.printfriendly.com/print?url=http%3A%2F%2Fwww.dealtaker.com%2Fblog%2F2009%2F06%2F19%2Fkohana-php-tuturial-part-iii%2F&amp;partner=sociable" title="Print"><img src="http://www.dealtaker.com/blog/wp-content/plugins/sociable/images/printfriendly.png" title="Print" alt="Print" class="sociable-hovers" /></a></li>
</ul>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.dealtaker.com/blog/2009/06/19/kohana-php-tuturial-part-iii/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
		</item>
		<item>
		<title>The Wonderful World of APIs</title>
		<link>http://www.dealtaker.com/blog/2009/06/16/the-wonderful-world-of-apis/</link>
		<comments>http://www.dealtaker.com/blog/2009/06/16/the-wonderful-world-of-apis/#comments</comments>
		<pubDate>Tue, 16 Jun 2009 13:38:42 +0000</pubDate>
		<dc:creator>smccarthy</dc:creator>
				<category><![CDATA[technology]]></category>
		<category><![CDATA[API]]></category>
		<category><![CDATA[eBay]]></category>
		<category><![CDATA[Facebook]]></category>
		<category><![CDATA[Linkedin]]></category>
		<category><![CDATA[MySpace]]></category>
		<category><![CDATA[Twitter]]></category>
		<category><![CDATA[YouTube]]></category>

		<guid isPermaLink="false">http://www.dealtaker.com/blog/?p=846</guid>
		<description><![CDATA[The Wonderful World of APIs
API or Application Programming Interface is a ubiquitous term used in the tech world everyday.Â  With the popularity of online social networking sites and the need to add features and content easily into your own site, executives are starting to understand the benefits of using and or providing a public API [...]]]></description>
			<content:encoded><![CDATA[<p>The Wonderful World of APIs</p>
<p>API or Application Programming Interface is a ubiquitous term used in the tech world everyday.Â  With the popularity of online social networking sites and the need to add features and content easily into your own site, executives are starting to understand the benefits of using and or providing a public API to third party organizations.Â  The term has become so popular that most executives now use API in their repertoire of business terms.Â  They should, considering users want these features and most organizations such as <a href="http://salesforce.com/" target="_blank">Salesforce.com</a>, <a href="http://www.youtube.com/dev" target="_blank">YouTube</a>, <a href="http://developer.ebay.com/common/api/" target="_blank">eBay</a>, <a href="http://apiwiki.twitter.com/" target="_blank">Twitter</a>, <a href="http://developers.facebook.com/" target="_blank">FaceBook</a>, <a href="http://developer.myspace.com/community/" target="_blank">MySpace</a> and <a href="http://www.linkedin.com/static?key=developers_apis" target="_blank">LinkedIn</a> provide an API for the public.Â  So, what exactly is an API?</p>
<p><span id="more-846"></span></p>
<p>APIs allow you to integrate third party content or features into your web site or web application using a set of common programming tools.Â  Basically, an API puts you in control of the data and how you want to present it.Â  It provides flexible, two-way communication and allows you to expand or enhance existing functionality.Â  APIs give you more control and greater options for integration than widgets or RSS feeds, but obviously require you to write more code in order to integrate it into your own applications.</p>
<p>One popular application called <a href="http://www.tweetdeck.com/beta/" target="_blank">TweetDeck</a> uses the Twitter API to enhance and expand Twitterâ€™s features.Â  TweetDeck is an Adobe <a href="http://www.adobe.com/products/air/" target="_blank">Air</a> application that runs on your Mac or PC desktop.Â  TweetDeck provides many benefits.Â  For one, it provides a continuous stream of tweets without having to constantly hit the refresh button.Â  It helps you organize tweets by columns giving you a so-called tweet dashboard.Â  It also allows you to easily isolate users you follow by clicking on their icon and viewing their profile.Â  You can then view stats about that user.</p>
<p>Although the current features and benefits of TweetDeck are abundant, it only exists because of Twitterâ€™s API and its ability to provide functionality Twitter has yet to offer.Â  This is of course good for Twitter, considering that 80% of their tweets or traffic comes through their API usage.</p>
<p>I&#8217;ve used the eBay and the YouTube API with great success in the past and look forward to providing one for DealTaker in the very near future.</p>
<p>The bottom line is this, APIs help both parties by allowing the reuse of features and content extending the existing business model while using less upfront investment.</p>

<div class="sociable">
<div class="sociable_tagline">
<strong>Share and Enjoy:</strong>
</div>
<ul>
	<li class="sociablefirst"><a rel="nofollow"  target="_blank" href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fwww.dealtaker.com%2Fblog%2F2009%2F06%2F16%2Fthe-wonderful-world-of-apis%2F&amp;title=The%20Wonderful%20World%20of%20APIs&amp;bodytext=The%20Wonderful%20World%20of%20APIs%0D%0A%0D%0AAPI%20or%20Application%20Programming%20Interface%20is%20a%20ubiquitous%20term%20used%20in%20the%20tech%20world%20everyday.%C3%82%C2%A0%20With%20the%20popularity%20of%20online%20social%20networking%20sites%20and%20the%20need%20to%20add%20features%20and%20content%20easily%20into%20your%20own%20site" title="Digg"><img src="http://www.dealtaker.com/blog/wp-content/plugins/sociable/images/digg.png" title="Digg" alt="Digg" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://delicious.com/post?url=http%3A%2F%2Fwww.dealtaker.com%2Fblog%2F2009%2F06%2F16%2Fthe-wonderful-world-of-apis%2F&amp;title=The%20Wonderful%20World%20of%20APIs&amp;notes=The%20Wonderful%20World%20of%20APIs%0D%0A%0D%0AAPI%20or%20Application%20Programming%20Interface%20is%20a%20ubiquitous%20term%20used%20in%20the%20tech%20world%20everyday.%C3%82%C2%A0%20With%20the%20popularity%20of%20online%20social%20networking%20sites%20and%20the%20need%20to%20add%20features%20and%20content%20easily%20into%20your%20own%20site" title="del.icio.us"><img src="http://www.dealtaker.com/blog/wp-content/plugins/sociable/images/delicious.png" title="del.icio.us" alt="del.icio.us" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://www.facebook.com/share.php?u=http%3A%2F%2Fwww.dealtaker.com%2Fblog%2F2009%2F06%2F16%2Fthe-wonderful-world-of-apis%2F&amp;t=The%20Wonderful%20World%20of%20APIs" title="Facebook"><img src="http://www.dealtaker.com/blog/wp-content/plugins/sociable/images/facebook.png" title="Facebook" alt="Facebook" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://twitter.com/home?status=The%20Wonderful%20World%20of%20APIs%20-%20http%3A%2F%2Fwww.dealtaker.com%2Fblog%2F2009%2F06%2F16%2Fthe-wonderful-world-of-apis%2F" title="Twitter"><img src="http://www.dealtaker.com/blog/wp-content/plugins/sociable/images/twitter.png" title="Twitter" alt="Twitter" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fwww.dealtaker.com%2Fblog%2F2009%2F06%2F16%2Fthe-wonderful-world-of-apis%2F&amp;title=The%20Wonderful%20World%20of%20APIs" title="StumbleUpon"><img src="http://www.dealtaker.com/blog/wp-content/plugins/sociable/images/stumbleupon.png" title="StumbleUpon" alt="StumbleUpon" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://www.mixx.com/submit?page_url=http%3A%2F%2Fwww.dealtaker.com%2Fblog%2F2009%2F06%2F16%2Fthe-wonderful-world-of-apis%2F&amp;title=The%20Wonderful%20World%20of%20APIs" title="Mixx"><img src="http://www.dealtaker.com/blog/wp-content/plugins/sociable/images/mixx.png" title="Mixx" alt="Mixx" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://www.google.com/bookmarks/mark?op=edit&amp;bkmk=http%3A%2F%2Fwww.dealtaker.com%2Fblog%2F2009%2F06%2F16%2Fthe-wonderful-world-of-apis%2F&amp;title=The%20Wonderful%20World%20of%20APIs&amp;annotation=The%20Wonderful%20World%20of%20APIs%0D%0A%0D%0AAPI%20or%20Application%20Programming%20Interface%20is%20a%20ubiquitous%20term%20used%20in%20the%20tech%20world%20everyday.%C3%82%C2%A0%20With%20the%20popularity%20of%20online%20social%20networking%20sites%20and%20the%20need%20to%20add%20features%20and%20content%20easily%20into%20your%20own%20site" title="Google Bookmarks"><img src="http://www.dealtaker.com/blog/wp-content/plugins/sociable/images/googlebookmark.png" title="Google Bookmarks" alt="Google Bookmarks" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://reddit.com/submit?url=http%3A%2F%2Fwww.dealtaker.com%2Fblog%2F2009%2F06%2F16%2Fthe-wonderful-world-of-apis%2F&amp;title=The%20Wonderful%20World%20of%20APIs" title="Reddit"><img src="http://www.dealtaker.com/blog/wp-content/plugins/sociable/images/reddit.png" title="Reddit" alt="Reddit" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://technorati.com/faves?add=http%3A%2F%2Fwww.dealtaker.com%2Fblog%2F2009%2F06%2F16%2Fthe-wonderful-world-of-apis%2F" title="Technorati"><img src="http://www.dealtaker.com/blog/wp-content/plugins/sociable/images/technorati.png" title="Technorati" alt="Technorati" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://buzz.yahoo.com/submit/?submitUrl=http%3A%2F%2Fwww.dealtaker.com%2Fblog%2F2009%2F06%2F16%2Fthe-wonderful-world-of-apis%2F&amp;submitHeadline=The%20Wonderful%20World%20of%20APIs&amp;submitSummary=The%20Wonderful%20World%20of%20APIs%0D%0A%0D%0AAPI%20or%20Application%20Programming%20Interface%20is%20a%20ubiquitous%20term%20used%20in%20the%20tech%20world%20everyday.%C3%82%C2%A0%20With%20the%20popularity%20of%20online%20social%20networking%20sites%20and%20the%20need%20to%20add%20features%20and%20content%20easily%20into%20your%20own%20site&amp;submitCategory=science&amp;submitAssetType=text" title="Yahoo! Buzz"><img src="http://www.dealtaker.com/blog/wp-content/plugins/sociable/images/yahoobuzz.png" title="Yahoo! Buzz" alt="Yahoo! Buzz" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://www.myspace.com/Modules/PostTo/Pages/?u=http%3A%2F%2Fwww.dealtaker.com%2Fblog%2F2009%2F06%2F16%2Fthe-wonderful-world-of-apis%2F&amp;t=The%20Wonderful%20World%20of%20APIs" title="MySpace"><img src="http://www.dealtaker.com/blog/wp-content/plugins/sociable/images/myspace.png" title="MySpace" alt="MySpace" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://www.linkedin.com/shareArticle?mini=true&amp;url=http%3A%2F%2Fwww.dealtaker.com%2Fblog%2F2009%2F06%2F16%2Fthe-wonderful-world-of-apis%2F&amp;title=The%20Wonderful%20World%20of%20APIs&amp;source=Inside+DealTaker+All+Things+Deal+Oriented&amp;summary=The%20Wonderful%20World%20of%20APIs%0D%0A%0D%0AAPI%20or%20Application%20Programming%20Interface%20is%20a%20ubiquitous%20term%20used%20in%20the%20tech%20world%20everyday.%C3%82%C2%A0%20With%20the%20popularity%20of%20online%20social%20networking%20sites%20and%20the%20need%20to%20add%20features%20and%20content%20easily%20into%20your%20own%20site" title="LinkedIn"><img src="http://www.dealtaker.com/blog/wp-content/plugins/sociable/images/linkedin.png" title="LinkedIn" alt="LinkedIn" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="https://favorites.live.com/quickadd.aspx?marklet=1&amp;url=http%3A%2F%2Fwww.dealtaker.com%2Fblog%2F2009%2F06%2F16%2Fthe-wonderful-world-of-apis%2F&amp;title=The%20Wonderful%20World%20of%20APIs" title="Live"><img src="http://www.dealtaker.com/blog/wp-content/plugins/sociable/images/live.png" title="Live" alt="Live" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="mailto:?subject=The%20Wonderful%20World%20of%20APIs&amp;body=http%3A%2F%2Fwww.dealtaker.com%2Fblog%2F2009%2F06%2F16%2Fthe-wonderful-world-of-apis%2F" title="email"><img src="http://www.dealtaker.com/blog/wp-content/plugins/sociable/images/email_link.png" title="email" alt="email" class="sociable-hovers" /></a></li>
	<li class="sociablelast"><a rel="nofollow"  target="_blank" href="http://www.printfriendly.com/print?url=http%3A%2F%2Fwww.dealtaker.com%2Fblog%2F2009%2F06%2F16%2Fthe-wonderful-world-of-apis%2F&amp;partner=sociable" title="Print"><img src="http://www.dealtaker.com/blog/wp-content/plugins/sociable/images/printfriendly.png" title="Print" alt="Print" class="sociable-hovers" /></a></li>
</ul>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.dealtaker.com/blog/2009/06/16/the-wonderful-world-of-apis/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>The Other Side of The Deal</title>
		<link>http://www.dealtaker.com/blog/2009/06/15/the-other-side-of-the-deal/</link>
		<comments>http://www.dealtaker.com/blog/2009/06/15/the-other-side-of-the-deal/#comments</comments>
		<pubDate>Mon, 15 Jun 2009 13:03:09 +0000</pubDate>
		<dc:creator>Kstraw</dc:creator>
				<category><![CDATA[DealTaker]]></category>
		<category><![CDATA[technology]]></category>

		<guid isPermaLink="false">http://www.dealtaker.com/blog/?p=1005</guid>
		<description><![CDATA[Energi-To-Go comes as advertised.]]></description>
			<content:encoded><![CDATA[<p>On June 9th I tweeted a great deal I saw on DealTaker.Â  Not all that uncommon &#8211; I see many great deals each week that I try to proliferate to my friands and family as much as possible.Â  This item was the Energizer Energi-To-Go cell phone batter back-up.Â  The cost for the product was $9.99 andÂ had free shipping.Â  The special part of the deal was that once the item was received, a survey would be enclosed that provided a $10.00 rebateÂ when the survey was completed.Â  I am happy to report that the item arrived sooner than I expected, was packaged well and as expected, and aÂ survey was in the packaging as promised.Â Â I filled it out, and am now awaiting the arrival of a check.Â Â For 10 minutes worth of work, I getÂ a free item.Â  Plus, I got to participate in a deal.Â  It is the little things in life sometimes that make it fun.Â  In this case &#8211; very small.Â  The bonus:Â  I also got a $2.00 off coupon for some more batteried when needed.Â  Stealing and enhancing a line from &#8220;Hannibal&#8221; Smith of <a href="http://en.wikipedia.org/wiki/The_A-Team#Characters" target="_blank">the A Team </a>- &#8220;I love it when a deal comes together&#8221;.</p>

<div class="sociable">
<div class="sociable_tagline">
<strong>Share and Enjoy:</strong>
</div>
<ul>
	<li class="sociablefirst"><a rel="nofollow"  target="_blank" href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fwww.dealtaker.com%2Fblog%2F2009%2F06%2F15%2Fthe-other-side-of-the-deal%2F&amp;title=The%20Other%20Side%20of%20The%20Deal&amp;bodytext=Energi-To-Go%20comes%20as%20advertised." title="Digg"><img src="http://www.dealtaker.com/blog/wp-content/plugins/sociable/images/digg.png" title="Digg" alt="Digg" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://delicious.com/post?url=http%3A%2F%2Fwww.dealtaker.com%2Fblog%2F2009%2F06%2F15%2Fthe-other-side-of-the-deal%2F&amp;title=The%20Other%20Side%20of%20The%20Deal&amp;notes=Energi-To-Go%20comes%20as%20advertised." title="del.icio.us"><img src="http://www.dealtaker.com/blog/wp-content/plugins/sociable/images/delicious.png" title="del.icio.us" alt="del.icio.us" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://www.facebook.com/share.php?u=http%3A%2F%2Fwww.dealtaker.com%2Fblog%2F2009%2F06%2F15%2Fthe-other-side-of-the-deal%2F&amp;t=The%20Other%20Side%20of%20The%20Deal" title="Facebook"><img src="http://www.dealtaker.com/blog/wp-content/plugins/sociable/images/facebook.png" title="Facebook" alt="Facebook" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://twitter.com/home?status=The%20Other%20Side%20of%20The%20Deal%20-%20http%3A%2F%2Fwww.dealtaker.com%2Fblog%2F2009%2F06%2F15%2Fthe-other-side-of-the-deal%2F" title="Twitter"><img src="http://www.dealtaker.com/blog/wp-content/plugins/sociable/images/twitter.png" title="Twitter" alt="Twitter" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fwww.dealtaker.com%2Fblog%2F2009%2F06%2F15%2Fthe-other-side-of-the-deal%2F&amp;title=The%20Other%20Side%20of%20The%20Deal" title="StumbleUpon"><img src="http://www.dealtaker.com/blog/wp-content/plugins/sociable/images/stumbleupon.png" title="StumbleUpon" alt="StumbleUpon" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://www.mixx.com/submit?page_url=http%3A%2F%2Fwww.dealtaker.com%2Fblog%2F2009%2F06%2F15%2Fthe-other-side-of-the-deal%2F&amp;title=The%20Other%20Side%20of%20The%20Deal" title="Mixx"><img src="http://www.dealtaker.com/blog/wp-content/plugins/sociable/images/mixx.png" title="Mixx" alt="Mixx" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://www.google.com/bookmarks/mark?op=edit&amp;bkmk=http%3A%2F%2Fwww.dealtaker.com%2Fblog%2F2009%2F06%2F15%2Fthe-other-side-of-the-deal%2F&amp;title=The%20Other%20Side%20of%20The%20Deal&amp;annotation=Energi-To-Go%20comes%20as%20advertised." title="Google Bookmarks"><img src="http://www.dealtaker.com/blog/wp-content/plugins/sociable/images/googlebookmark.png" title="Google Bookmarks" alt="Google Bookmarks" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://reddit.com/submit?url=http%3A%2F%2Fwww.dealtaker.com%2Fblog%2F2009%2F06%2F15%2Fthe-other-side-of-the-deal%2F&amp;title=The%20Other%20Side%20of%20The%20Deal" title="Reddit"><img src="http://www.dealtaker.com/blog/wp-content/plugins/sociable/images/reddit.png" title="Reddit" alt="Reddit" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://technorati.com/faves?add=http%3A%2F%2Fwww.dealtaker.com%2Fblog%2F2009%2F06%2F15%2Fthe-other-side-of-the-deal%2F" title="Technorati"><img src="http://www.dealtaker.com/blog/wp-content/plugins/sociable/images/technorati.png" title="Technorati" alt="Technorati" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://buzz.yahoo.com/submit/?submitUrl=http%3A%2F%2Fwww.dealtaker.com%2Fblog%2F2009%2F06%2F15%2Fthe-other-side-of-the-deal%2F&amp;submitHeadline=The%20Other%20Side%20of%20The%20Deal&amp;submitSummary=Energi-To-Go%20comes%20as%20advertised.&amp;submitCategory=science&amp;submitAssetType=text" title="Yahoo! Buzz"><img src="http://www.dealtaker.com/blog/wp-content/plugins/sociable/images/yahoobuzz.png" title="Yahoo! Buzz" alt="Yahoo! Buzz" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://www.myspace.com/Modules/PostTo/Pages/?u=http%3A%2F%2Fwww.dealtaker.com%2Fblog%2F2009%2F06%2F15%2Fthe-other-side-of-the-deal%2F&amp;t=The%20Other%20Side%20of%20The%20Deal" title="MySpace"><img src="http://www.dealtaker.com/blog/wp-content/plugins/sociable/images/myspace.png" title="MySpace" alt="MySpace" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://www.linkedin.com/shareArticle?mini=true&amp;url=http%3A%2F%2Fwww.dealtaker.com%2Fblog%2F2009%2F06%2F15%2Fthe-other-side-of-the-deal%2F&amp;title=The%20Other%20Side%20of%20The%20Deal&amp;source=Inside+DealTaker+All+Things+Deal+Oriented&amp;summary=Energi-To-Go%20comes%20as%20advertised." title="LinkedIn"><img src="http://www.dealtaker.com/blog/wp-content/plugins/sociable/images/linkedin.png" title="LinkedIn" alt="LinkedIn" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="https://favorites.live.com/quickadd.aspx?marklet=1&amp;url=http%3A%2F%2Fwww.dealtaker.com%2Fblog%2F2009%2F06%2F15%2Fthe-other-side-of-the-deal%2F&amp;title=The%20Other%20Side%20of%20The%20Deal" title="Live"><img src="http://www.dealtaker.com/blog/wp-content/plugins/sociable/images/live.png" title="Live" alt="Live" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="mailto:?subject=The%20Other%20Side%20of%20The%20Deal&amp;body=http%3A%2F%2Fwww.dealtaker.com%2Fblog%2F2009%2F06%2F15%2Fthe-other-side-of-the-deal%2F" title="email"><img src="http://www.dealtaker.com/blog/wp-content/plugins/sociable/images/email_link.png" title="email" alt="email" class="sociable-hovers" /></a></li>
	<li class="sociablelast"><a rel="nofollow"  target="_blank" href="http://www.printfriendly.com/print?url=http%3A%2F%2Fwww.dealtaker.com%2Fblog%2F2009%2F06%2F15%2Fthe-other-side-of-the-deal%2F&amp;partner=sociable" title="Print"><img src="http://www.dealtaker.com/blog/wp-content/plugins/sociable/images/printfriendly.png" title="Print" alt="Print" class="sociable-hovers" /></a></li>
</ul>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.dealtaker.com/blog/2009/06/15/the-other-side-of-the-deal/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
