Some Examples

Kohana 2nd Note:

  1. hello world! is within welcome.php located in application/classes/controller directory. It is the default controller. The code inside welcome.php is:
  2. <?php defined(‘SYSPATH’) or die(‘No direct script access.’);

    class Controller_Welcome extends Controller {

    public function action_index()


    $this->request->response = ‘hello, world!’;


    } // End Welcome

  3. These are some of the important files and their location to be aware of:




Let’s create a test script and call it try1.php and upload it to application/classes/controller directory. This is the deafault controller path. The default controller is welcome.php.

try1.php is :

<?php defined(‘SYSPATH’) or die(‘No direct script access.’);

class Controller_Try1 extends Controller {

public function action_index()


echo ‘<p>Executing try1.php</p>’;

echo ‘<p>More paragraph.</p>’;

$this->request->response = ‘Using request response to display this line.’;


} // End Welcome

Some notes about try1.php:

Controller is a Kohana class. All application controllers will extend this class. Your application may have just one controller, or it may have many, depending on how it is organised. A single method, index() is defined. If the controller is invoked without a method segment, this function is called.

Ability to choose from several functions within a controller:

Create a file named application/classes/controller/hello.php with these codes in it:

<?php defined(‘SYSPATH’) OR die(‘No Direct Script Access’);

Class Controller_Hello extends Controller_Template{

public $template = ‘site’;

function action_index() {

$this->template->message = ‘hello, world! from Function index within hello.php.’;


function action_x() {

$this->template->message = ‘Running Function x within hello.php!’;



Create another file named application/views/site.php with these codes in it:



<title>We’ve got a message for you!</title>

<style type=”text/css”> body {font-family: Georgia;} h1 {font-style: italic;} h2 {font-style:oblique} </style></head>


<h1><?php echo $message; ?></h1>

<h2>Note: Above comment is passed from hello.php to this site.php.</h2>

<p> This line and above line (Note: A…) are strictly being displayed from within site.php</p>



You can select with function from within hello.php to be executed by loading one of these urls:

This will run index() function of hello.php

This will run x function of hello.php


Jay Kajavi

Installing Kohana – Basic Steps

Installing Kohana:

My Server Specs:

PHP Version: 5.2.3

Apache 2.2.15

MySQL 5.0.91-community

Let’s install it:

  1. Downloaded and unzipped Kohana 3.0.7 on my Windows machine
  2. Upload to Server
  3. Edit application/bootstrap.php: Time zone Canada/Pacific, and base_url to appropriate path. By default base_url was set to / . I changed it to /directorywhereiinstalledkohana. (Reference:
  4. Application/logs and cache are 755 by default
  5. Loading was successful. It reports the Environment Tests have passed. Loading reports the same.
  6. Rename install.php
  7. When you load up in your browser, you should see hello, world! message. If you don’t see it, then reload the page in your browser (F5). When I loaded I get the same message of hello, wold! (Renaming install.php in above step is causing this change in behavior which is normal).

Jay Kajavi