<?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 DealTakerinstall » Inside DealTaker</title>
	<atom:link href="http://www.dealtaker.com/our-blog/tag/install/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.dealtaker.com/our-blog</link>
	<description>Just another DealTaker.com site</description>
	<lastBuildDate>Fri, 10 Feb 2012 14:56:55 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=</generator>
		<item>
		<title>Kohana PHP 2.3.x Tutorial Part 1</title>
		<link>http://www.dealtaker.com/our-blog/2009/04/23/kohana-php-23x-tutorial-part-1/</link>
		<comments>http://www.dealtaker.com/our-blog/2009/04/23/kohana-php-23x-tutorial-part-1/#comments</comments>
		<pubDate>Thu, 23 Apr 2009 09:22:25 +0000</pubDate>
		<dc:creator>ellisgl</dc:creator>
				<category><![CDATA[DealTaker.com Updates]]></category>
		<category><![CDATA[controllers]]></category>
		<category><![CDATA[framework]]></category>
		<category><![CDATA[install]]></category>
		<category><![CDATA[kohana]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://www.dealtaker.com/blog/?p=558</guid>
		<description><![CDATA[So after reading my article about frameworks, you might want to try one out. Today we are going start a series of tutorials on how to use the Kohana PHP framework beginning with how to install it and creating a controller. Before we get into this tutorial, lets go over what will be required. *AMP [...]]]></description>
			<content:encoded><![CDATA[<p>So after reading <a href="http://www.dealtaker.com/blog/2009/02/10/frameworks-frameworks-frameworks/">my article about frameworks</a>, you might want to try one out. Today we are going start a series of tutorials on how to use the Kohana PHP framework beginning with how to install it and creating a controller.<br />
<span id="more-558"></span></p>
<p>Before we get into this tutorial, lets go over what will be required.</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 get started!<br />
Download:<br />
Load <a href="http://kohanaframework.org//">http://www.kohanaphp.com</a> in your favorite browser and click the Download Kohana! button. You should be prompted to save a file. Go a head and save the file some where. At the time of this writing, the version was at 2.3.2.</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_v2.3.2&#8243; or something like that. Open that folder. Open a new window and open the root directory of your *AMP install. Since I&#8217;m using WAMP Server &#8211; mine is C:wampwww. Next make a new folder in there named &#8220;myfirstkohana&#8221;. Copy the files from the &#8220;Kohana_v2.3.2&#8243; directory to the &#8220;myfirstkohana&#8221;.  Make sure your *AMP installation is up and running then point your browser to http://yourserver/myfirstkohana/ . You should have a screen stating that everything is &#8220;OK&#8221;.<br />
<img src="http://images.dealtaker.com/dealtaker/blog/kohana/kohana-1-1.png" alt="" /></p>
<p>If everything is &#8220;OK&#8221;, then remove or rename the &#8220;install.php&#8221; file in the &#8220;myfirstkohana&#8221; directory. Next we want to navigate into the application folder, then in the the config folder. Open the file named &#8220;config.php&#8221; in your favorite editor. There should be a line that reads: &#8220;$config['site_domain'] = &#8216;/kohana/&#8217;;&#8221; (Line 7 for me). We need to change the &#8220;/kohana/&#8221; part to reflect our install. So replace &#8220;/kohana/&#8221; with &#8220;/myfirstkohana/&#8221;. Also search for &#8220;$config['index_page'] = &#8216;index.php&#8217;;&#8221; and make the &#8220;index.php&#8221; part blank, so that line (Line 21 for me) should now read &#8220;$config['index_page'] = &#8221;;&#8221;.  Save that file.</p>
<p>Create a new document, cut and paste the following into it:</p>
<pre># Turn on URL rewriting
RewriteEngine On

# Put your installation directory here:
# If your URL is www.example.com/, use /
# If your URL is www.example.com/kohana/, use /kohana/
RewriteBase /myfirstkohana/

# Do not enable rewriting for files or directories that exist
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

# For reuests that are not actual files or directories,
# Rewrite to index.php/URL
RewriteRule ^(.*)$ index.php/$1 [PT,L]</pre>
<p>Save this file in the &#8220;myfirstkohana&#8221; directory as &#8220;.htaccess&#8221;.</p>
<p>These changes will help with creating clean URLs that help with SEO efforts.</p>
<p>Reload the browser page and you should get something like this:<br />
<img src="http://images.dealtaker.com/dealtaker/blog/kohana/kohana-1-2.png" alt="" /></p>
<p>If everything looks good, then we have successfully installed Kohana PHP.  Now lets make it do stuff!</p>
<p>My first controller:<br />
Open a new document and put the following into it:</p>
<pre>&lt;?php
defined('SYSPATH') or die('No direct access allowed.');

class Hello_Controller extends Controller
 {
  public function index()
   {
    echo 'Hello World!';
   }
 }</pre>
<p>Save this in &#8220;myfirstkohana/application/controllers&#8221; as &#8220;hello.php&#8221;. Here&#8217;s a little explaination of what we did. The line &#8220;defined(&#8216;SYSPATH&#8217;) or die(&#8216;No direct access allowed.&#8217;);&#8221; basically prevents the file from being executed by itself. The next line &#8220;class Hello_Controller extends Controller&#8221; creates a class called &#8220;Hello_Controller&#8221; that extends the controller object. The rules to follow for creating controllers is as follows:</p>
<ul>
<li>Must reside in a controllers (sub-)directory</li>
<li>Controller filename must be lowercase, e.g. articles.php</li>
<li>Controller class must map to filename and capitalized, and must be appended with _Controller, e.g. Articles_Controller</li>
<li>Must have the Controller class as (grand)parent</li>
<li>Controller methods preceded by &#8216;_&#8217; (e.g. _do_something() ) cannot be called by the URI mapping</li>
</ul>
<p>stolen from: <a href="http://docs.kohanaphp.com/general/controllers">Kohana Docs</a></p>
<p>The first method, &#8220;index&#8221; is the default action. Pretty easy right? If you point your browser to &#8220;http://yourserver/myfirstkohana/hello/&#8221; you should see &#8220;Hello World!&#8221; on the screen now.</p>
<p>What if you wanted to exend the controller to do something else? Let add another method in the class that looks like:</p>
<pre>public function america()
 {
  echo 'Hello America!';
 }</pre>
<p>Now the hello.php should look like:</p>
<pre>&lt;?php
defined('SYSPATH') or die('No direct access allowed.');

class Hello_Controller extends Controller
 {
  public function index()
   {
    echo 'Hello World!';
   }

  public function america()
   {
    echo 'Hello America!';
   }
 }</pre>
<p>Save this and open &#8220;http://yourserver/hello/america/&#8221;. Notice that is now show &#8220;Hello America!&#8221; on the screen. That wasn&#8217;t too hard, but lets make this a little more dynamic with arguements. Make a new method that will look like this:</p>
<pre>public function name($name)
 {
  echo 'Hello ',$name,'!';
 }</pre>
<p>Load up &#8220;http://yourserver/hello/name/monkey&#8221; and you should see &#8220;Hello monkey!&#8221; on your screen. Pretty straight forward. Let make it even more &#8216;friendly&#8217;. Add this to the top of the class:</p>
<pre>public function __call($method, $arguments)
 {
  $this-&gt;name($method);
 }</pre>
<p>If we load up &#8220;http://yourserver/myfirstkohana/hello/MrGuy/&#8221; we should get the same thing as if we loaded &#8220;http://yourserver/myfirstkohana/hello/name/MrGuy/&#8221; which would be &#8220;Hello MrGuy!&#8221;.</p>
<p>That&#8217;s it for this lesson. Next time we&#8217;ll be looking over Views.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dealtaker.com/our-blog/2009/04/23/kohana-php-23x-tutorial-part-1/feed/</wfw:commentRss>
		<slash:comments>13</slash:comments>
		</item>
	</channel>
</rss>

