<?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>Adam Tootle &#187; Programming</title>
	<atom:link href="http://www.adamtootle.com/category/programming/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.adamtootle.com</link>
	<description>Savannah-based web developer, musician, and Christian</description>
	<lastBuildDate>Wed, 13 Jul 2011 19:26:06 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Kohana Hello World</title>
		<link>http://www.adamtootle.com/2010/06/kohana-hello-world/</link>
		<comments>http://www.adamtootle.com/2010/06/kohana-hello-world/#comments</comments>
		<pubDate>Sat, 12 Jun 2010 16:13:09 +0000</pubDate>
		<dc:creator>adam</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[beginner]]></category>
		<category><![CDATA[hello world]]></category>
		<category><![CDATA[kohana]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://www.adamtootle.com/?p=92</guid>
		<description><![CDATA[Kohana is quite and amazing tool to use in PHP application development. It&#8217;s an awesome MVC framework and can make development time way faster. I&#8217;m not getting into framework comparisons, as I mainly work in Kohana (when I&#8217;m not working in WordPress). This is a quick tutorial on a simple &#8216;hello world&#8217; application (because every [...]]]></description>
			<content:encoded><![CDATA[<p>Kohana is quite and amazing tool to use in PHP application development. It&#8217;s an awesome MVC framework and can make development time way faster. I&#8217;m not getting into framework comparisons, as I mainly work in Kohana (when I&#8217;m not working in WordPress). This is a quick tutorial on a simple &#8216;hello world&#8217; application (because every first time developer should always write a hello world app, it&#8217;s the rules).</p>
<p>Before we get started, go ahead and grab the latest version of Kohana <a href="http://kohanaframework.org/download" target="_blank">here</a>. I&#8217;ll be using v2.3.4.</p>
<h3>1) Install Kohana</h3>
<p>Which really means just copy the Kohana files into the directory you are going to be working in. For the sake of this tutorial, let&#8217;s put it in a directory name /helloworld/. Let the install.php script execute and tell you everything is good to go. I&#8217;m not addressing server errors in this tutorial (but I am assuming you&#8217;re on Apache). After everything is cleared, you can either rename the install.php or delete it.</p>
<h3>2) Setup .htaccess</h3>
<p>I usually go ahead and setup the .htaccess file. This way I don&#8217;t have to worry about troubleshooting this later. Kohana provides an example.htaccess file. Grab the contents of this and paste it into our .htaccess file in the root directory of the application (helloworld/). The only thing we are going to change is the line that reads &#8216;RewriteBase /kohana/&#8217;. We need this to say &#8216;RewriteBase /helloworld/&#8217; (no quotes). This just tells the server what we will be running our application from the helloworld/ directory.</p>
<h3>3) Create Our Controller</h3>
<p>Kohana follows a strict naming convention for certain files in our application. For our &#8216;hello world&#8217; application, we are just going to create a &#8216;hello&#8217; controller. Create a file named hello.php in our /application/controllers/ directory. This is going to be the main controller for this application.</p>
<h3>4) Start coding</h3>
<p>Let&#8217;s jump in and start writing code and I will explain it as we go along.</p>
<p>First, add this line to the top of the hello.php (after our opening &lt;?php tag, of course):</p>
<pre class="brush: php; title: ; notranslate">

defined('SYSPATH') OR die('No direct access allowed.');
</pre>
<p>This is helps with a security issue that I&#8217;m not going to get into right now. You should always add this to each of your controllers.</p>
<p>Next, let&#8217;s go ahead and declare our class:</p>
<pre class="brush: php; title: ; notranslate">

class Hello_Controller extends Controller{

}
</pre>
<p>This is where the naming convention can really be seen. Because we are declaring a controller for hello, the file name <span style="text-decoration: underline;">must be</span> lower case. Also, the class declaration <span style="text-decoration: underline;">must</span> match the filename, be capital case, and end in _Controller. Our class also extends the Controller class, which gives us access to all of Kohana&#8217;s core features for this class.</p>
<p>Example: a blog controller would have the filename &#8216;blog.php&#8217;, be declared as Blog_Controller, and extend Controller.</p>
<h3>5) Add Index Function</h3>
<p>Let&#8217;s go a head and add an index function to our Hello_Controller class.</p>
<pre class="brush: php; title: ; notranslate">

class Hello_Controller extends Controller{

    function index(){

        echo 'hello world!';

    }

}
</pre>
<p>I&#8217;ll cover this a little more in the next step.</p>
<h3>6) Test It</h3>
<p>At this point you should be able to access your controller. First, let&#8217;s look at how Kohana reads the url structure. This is an example of a basic call to a controller:</p>
<p>(application root)/controllerName/functionName</p>
<p>Therefore, we should be able to call our hello controller by accessing (your domain)/helloworld/hello/index. This calls the index function of our hello controller.</p>
<p>*hint* &#8211; you do not have to specify index in the url. If a function name is not given in the url, Kohana will look for the index function.</p>
<p>Accessing this function should give you our &#8216;hello world!&#8217; output from step 5.</p>
<h3>7) That&#8217;s it</h3>
<p>This was a quick and easy example of how to get a simple application up and running. I&#8217;ll cover using views and models soon.</p>


<div class="shr-bookmarks shr-bookmarks-expand shr-bookmarks-center shr-bookmarks-bg-enjoy">
<ul class="socials">
		<li class="shr-comfeed">
			<a href="http://www.adamtootle.com/2010/06/kohana-hello-world/feed" rel="nofollow" class="external" title="Subscribe to the comments for this post?">Subscribe to the comments for this post?</a>
		</li>
		<li class="shr-twitter">
			<a href="http://www.shareaholic.com/api/share/?title=Kohana+Hello+World&amp;link=http://www.adamtootle.com/2010/06/kohana-hello-world/&amp;notes=Kohana%20is%20quite%20and%20amazing%20tool%20to%20use%20in%20PHP%20application%20development.%20It%27s%20an%20awesome%20MVC%20framework%20and%20can%20make%20development%20time%20way%20faster.%20I%27m%20not%20getting%20into%20framework%20comparisons%2C%20as%20I%20mainly%20work%20in%20Kohana%20%28when%20I%27m%20not%20working%20in%20Wordpress%29.%20This%20is%20a%20quick%20tutorial%20on%20a%20simple%20%27hello%20worl&amp;short_link=&amp;shortener=none&amp;shortener_key=&amp;v=1&amp;apitype=1&amp;apikey=8afa39428933be41f8afdb8ea21a495c&amp;source=Shareaholic&amp;template=%2524%257Btitle%257D%2B-%2B%2524%257Bshort_link%257D&amp;service=7&amp;tags=&amp;ctype=" rel="nofollow" class="external" title="Tweet This!">Tweet This!</a>
		</li>
		<li class="shr-facebook">
			<a href="http://www.shareaholic.com/api/share/?title=Kohana+Hello+World&amp;link=http://www.adamtootle.com/2010/06/kohana-hello-world/&amp;notes=Kohana%20is%20quite%20and%20amazing%20tool%20to%20use%20in%20PHP%20application%20development.%20It%27s%20an%20awesome%20MVC%20framework%20and%20can%20make%20development%20time%20way%20faster.%20I%27m%20not%20getting%20into%20framework%20comparisons%2C%20as%20I%20mainly%20work%20in%20Kohana%20%28when%20I%27m%20not%20working%20in%20Wordpress%29.%20This%20is%20a%20quick%20tutorial%20on%20a%20simple%20%27hello%20worl&amp;short_link=&amp;shortener=none&amp;shortener_key=&amp;v=1&amp;apitype=1&amp;apikey=8afa39428933be41f8afdb8ea21a495c&amp;source=Shareaholic&amp;template=&amp;service=5&amp;tags=&amp;ctype=" rel="nofollow" title="Share this on Facebook">Share this on Facebook</a>
		</li>
		<li class="shr-digg">
			<a href="http://www.shareaholic.com/api/share/?title=Kohana+Hello+World&amp;link=http://www.adamtootle.com/2010/06/kohana-hello-world/&amp;notes=Kohana%20is%20quite%20and%20amazing%20tool%20to%20use%20in%20PHP%20application%20development.%20It%27s%20an%20awesome%20MVC%20framework%20and%20can%20make%20development%20time%20way%20faster.%20I%27m%20not%20getting%20into%20framework%20comparisons%2C%20as%20I%20mainly%20work%20in%20Kohana%20%28when%20I%27m%20not%20working%20in%20Wordpress%29.%20This%20is%20a%20quick%20tutorial%20on%20a%20simple%20%27hello%20worl&amp;short_link=&amp;shortener=none&amp;shortener_key=&amp;v=1&amp;apitype=1&amp;apikey=8afa39428933be41f8afdb8ea21a495c&amp;source=Shareaholic&amp;template=&amp;service=3&amp;tags=&amp;ctype=" rel="nofollow" class="external" title="Digg this!">Digg this!</a>
		</li>
		<li class="shr-reddit">
			<a href="http://www.shareaholic.com/api/share/?title=Kohana+Hello+World&amp;link=http://www.adamtootle.com/2010/06/kohana-hello-world/&amp;notes=Kohana%20is%20quite%20and%20amazing%20tool%20to%20use%20in%20PHP%20application%20development.%20It%27s%20an%20awesome%20MVC%20framework%20and%20can%20make%20development%20time%20way%20faster.%20I%27m%20not%20getting%20into%20framework%20comparisons%2C%20as%20I%20mainly%20work%20in%20Kohana%20%28when%20I%27m%20not%20working%20in%20Wordpress%29.%20This%20is%20a%20quick%20tutorial%20on%20a%20simple%20%27hello%20worl&amp;short_link=&amp;shortener=none&amp;shortener_key=&amp;v=1&amp;apitype=1&amp;apikey=8afa39428933be41f8afdb8ea21a495c&amp;source=Shareaholic&amp;template=&amp;service=40&amp;tags=&amp;ctype=" rel="nofollow" class="external" title="Share this on Reddit">Share this on Reddit</a>
		</li>
		<li class="shr-stumbleupon">
			<a href="http://www.shareaholic.com/api/share/?title=Kohana+Hello+World&amp;link=http://www.adamtootle.com/2010/06/kohana-hello-world/&amp;notes=Kohana%20is%20quite%20and%20amazing%20tool%20to%20use%20in%20PHP%20application%20development.%20It%27s%20an%20awesome%20MVC%20framework%20and%20can%20make%20development%20time%20way%20faster.%20I%27m%20not%20getting%20into%20framework%20comparisons%2C%20as%20I%20mainly%20work%20in%20Kohana%20%28when%20I%27m%20not%20working%20in%20Wordpress%29.%20This%20is%20a%20quick%20tutorial%20on%20a%20simple%20%27hello%20worl&amp;short_link=&amp;shortener=none&amp;shortener_key=&amp;v=1&amp;apitype=1&amp;apikey=8afa39428933be41f8afdb8ea21a495c&amp;source=Shareaholic&amp;template=&amp;service=38&amp;tags=&amp;ctype=" rel="nofollow" class="external" title="Stumble upon something good? Share it on StumbleUpon">Stumble upon something good? Share it on StumbleUpon</a>
		</li>
		<li class="shr-gmail">
			<a href="http://www.shareaholic.com/api/share/?title=Kohana+Hello+World&amp;link=http://www.adamtootle.com/2010/06/kohana-hello-world/&amp;notes=Kohana%20is%20quite%20and%20amazing%20tool%20to%20use%20in%20PHP%20application%20development.%20It%27s%20an%20awesome%20MVC%20framework%20and%20can%20make%20development%20time%20way%20faster.%20I%27m%20not%20getting%20into%20framework%20comparisons%2C%20as%20I%20mainly%20work%20in%20Kohana%20%28when%20I%27m%20not%20working%20in%20Wordpress%29.%20This%20is%20a%20quick%20tutorial%20on%20a%20simple%20%27hello%20worl&amp;short_link=&amp;shortener=none&amp;shortener_key=&amp;v=1&amp;apitype=1&amp;apikey=8afa39428933be41f8afdb8ea21a495c&amp;source=Shareaholic&amp;template=&amp;service=52&amp;tags=&amp;ctype=" rel="nofollow" class="external" title="Email this via Gmail">Email this via Gmail</a>
		</li>
		<li class="shr-linkedin">
			<a href="http://www.shareaholic.com/api/share/?title=Kohana+Hello+World&amp;link=http://www.adamtootle.com/2010/06/kohana-hello-world/&amp;notes=Kohana%20is%20quite%20and%20amazing%20tool%20to%20use%20in%20PHP%20application%20development.%20It%27s%20an%20awesome%20MVC%20framework%20and%20can%20make%20development%20time%20way%20faster.%20I%27m%20not%20getting%20into%20framework%20comparisons%2C%20as%20I%20mainly%20work%20in%20Kohana%20%28when%20I%27m%20not%20working%20in%20Wordpress%29.%20This%20is%20a%20quick%20tutorial%20on%20a%20simple%20%27hello%20worl&amp;short_link=&amp;shortener=none&amp;shortener_key=&amp;v=1&amp;apitype=1&amp;apikey=8afa39428933be41f8afdb8ea21a495c&amp;source=Shareaholic&amp;template=&amp;service=88&amp;tags=&amp;ctype=" rel="nofollow" class="external" title="Share this on LinkedIn">Share this on LinkedIn</a>
		</li>
		<li class="shr-tumblr">
			<a href="http://www.shareaholic.com/api/share/?title=Kohana+Hello+World&amp;link=http%3A%2F%2Fwww.adamtootle.com%2F2010%2F06%2Fkohana-hello-world%2F&amp;notes=Kohana%20is%20quite%20and%20amazing%20tool%20to%20use%20in%20PHP%20application%20development.%20It%27s%20an%20awesome%20MVC%20framework%20and%20can%20make%20development%20time%20way%20faster.%20I%27m%20not%20getting%20into%20framework%20comparisons%2C%20as%20I%20mainly%20work%20in%20Kohana%20%28when%20I%27m%20not%20working%20in%20Wordpress%29.%20This%20is%20a%20quick%20tutorial%20on%20a%20simple%20%27hello%20worl&amp;short_link=&amp;shortener=none&amp;shortener_key=&amp;v=1&amp;apitype=1&amp;apikey=8afa39428933be41f8afdb8ea21a495c&amp;source=Shareaholic&amp;template=&amp;service=78&amp;tags=&amp;ctype=" rel="nofollow" class="external" title="Share this on Tumblr">Share this on Tumblr</a>
		</li>
</ul><div style="clear: both;"></div><div class="shr-getshr" style="visibility:hidden;font-size:10px !important"><a target="_blank" href="http://www.shareaholic.com/?src=pub">Get Shareaholic</a></div><div style="clear: both;"></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.adamtootle.com/2010/06/kohana-hello-world/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

