<?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; controllers</title>
	<atom:link href="http://www.dealtaker.com/blog/tag/controllers/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.dealtaker.com/blog</link>
	<description>All Things Deal Oriented</description>
	<lastBuildDate>Fri, 19 Mar 2010 13:24:13 +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 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>
]]></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>Kohana PHP 2.3.x Tutorial Part 1</title>
		<link>http://www.dealtaker.com/blog/2009/04/23/kohana-php-23x-tutorial-part-1/</link>
		<comments>http://www.dealtaker.com/blog/2009/04/23/kohana-php-23x-tutorial-part-1/#comments</comments>
		<pubDate>Thu, 23 Apr 2009 15:22:25 +0000</pubDate>
		<dc:creator>ellisgl</dc:creator>
				<category><![CDATA[Uncategorized]]></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 (Apache MySQL [...]]]></description>
			<content:encoded><![CDATA[<p>So after reading <a href="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://www.kohanaphp.com/">http://www.kohanaphp.com</a> in your favorite browser and click the <a href="http://www.kohanaphp.com/download">download link</a>. On this page, click the &#8220;<a href="http://www.kohanaphp.com/download?languages%5Ben_US%5D=en_US&amp;format=zip">Download Kohana!</a>&#8221; 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:\wamp\www\. 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(&#8217;SYSPATH&#8217;) or die(&#8217;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.<br />
<a href="http://images.dealtaker.com/dealtaker/blog/kohana/dealtaker-kohana-1.zip">Click here</a> to download the files and don&#8217;t forget to check out some <a title="Tech Deals" href="http://www.dealtaker.com/tech-deals.html">great computer and electronic deals</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dealtaker.com/blog/2009/04/23/kohana-php-23x-tutorial-part-1/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
	</channel>
</rss>
