This is the first post in a new series on how to develop applications using the Kohana HMVC framework 3.0+. If you are unfamiliar with php, you should learn how to program with php first.
Today we are going to go over simple installation and configuration so that we have something to work with. I’m going to try and dumb it down for you guys so we can get some real work done real quick.
Go ahead and visit the Kohana website and download the latest version.
Download Kohana Here
Once you have it downloaded you are going to want to extract the archive and place all the files on your server. I will be using a localhost server named WAMP. Place the folder called “Kohana” in the root directory of your server. My root folder is called
www. So to clarify you will find the Kohana directory at
Now in your web browser (i’m using Firefox) navigate to
http://localhost/kohana, and what you should see is Environment Tests and a big list of tests, hopefully it looks like the image below. If you are this far, go ahead and do what it says and remove
kohana/install.php. So this sums up step 1, and we are actually close to being done already.
For step 2 we are going to open up the kohana folder and find the
kohana/application/bootsrap.php file, this is the main configuration file. Go to about line 52 and find:
52 53 54
Kohana::init(array( 'base_url' => '/' ));
and change that to look like this:
52 53 54 55
Kohana::init(array( 'base_url' => '/kohana', 'index_page' => '' ));
What we did here is told Kohana that our base_url is
/kohana so the full url would look like this
http://localhost/kohana , and for the index_page we dont want anything because we will be using an
.htaccess file to rewrite our urls. So normally a Kohana url would look like this
http://localhost/kohana/index.php/welcome and we will change it to look like
http://localhost/kohana/welcome. This is not only better to look at but helps with SEO purposes.
Next, in your kohana folder, find a file called
example.htaccess and open it. Notice the code shown below is at the very bottom of the file.
RewriteRule .* index.php/$0 [PT]
Currently, there is a problem with the way this rewrites so we will have to change that line to this:
RewriteRule ^(.+)$ index.php?kohana_uri=$1 [L]
Then rename the
example.htaccess file to
Lastly, in the bootstrap file, we are going to find
87 88 89 90 91
Route::set('default', '(<controller>(/<action>(/<id>)))') ->defaults(array( 'controller' => 'welcome', 'action' => 'index', ));
We aren’t going to do anything with this today, but ill tell you what it is for. The controller is exactly what it sounds like. It controls the page requests and data passed to each page. The action part is the default method that the controller will call. A sample url using the current route style
http://localhost/kohana/controller/action/id. As of now, if you go to
http://localhost/kohana/ you should see simply
That concludes the first Kohana tutorial. I hope you have learned how to successfully install the Kohana framework. Once we get into the more advanced tutorials, I’m sure you will grow more excited about using Kohana as it is a powerful and fast frame work; not bloated like Zend or others.
Next time, I will be going over the concepts of controllers and we will be building a very simple web page.
And if you haven't already, you should follow me on twitter!Follow @zackperdue