This is documentation for Kohana v2.3.x. For v3.x documentation, see .

Table of Contents
StatusFirst Draft
TodoRequires more development


Users of Kohana version 1.x (“Blueflame”) or CodeIgniter 1.x migrating to Kohana 2.0 can follow these steps to migrate their application.


Starting with a fresh Kohana install, delete application folder, and copy your existing application folder to the same location.


Remove your old config folder.

  1. Copy the application/config directory from Kohana 2.x to application/config
  2. Edit application/config/config.php, the main configuration files for your application
  3. Review the User Guide: Configuration page


The logs directory needs to be writable by the webserver or you can turn logging off.

Class Names

Rename all your controllers to {NAME}_Controller. For example, if your old controller was Page, make it Page_Controller.

Make your Controller contructors PHP5 if needed:

  1. function __construct() instead of function Page()
  2. parent::__construct() instead of parent::Controller()
  3. Note: This also applies to Models!

Rename all your models to {NAME}_Model

  1. For example, if your old model was PageModel, make it Page_Model
  2. Change all your model loads to just model name: $this→load→model('page')
  3. If you add a __construct() function, be sure to call parent::__construct()


Base Controllers

If you have a base controller for your application (in the libraries folder) you will need to:

  1. Change the MY_Controller extends Controller to Controller extends Controller_Core
  2. Change references to MY_Controller in your controllers to Controller
  3. Use the PHP5 syntax for the constructor in your base controller


The CI function uri_to_assoc($offset) becomes segment_array($offset,$associative) with $associative set to TRUE.


Class names need to have _Core appended to them and be capitalized. The file names should also have the same caps as the class name (without the core).

References to those classes need to be capitalized to match the library calls (without the core).

$this→load→ is deprecated. Kohana uses auto loading so you can instantiate an object (e.g. new View()) without including the class first.


Change all your helper calls to the new syntax: helper::function()

  1. Example: html::anchor() instead of anchor()
  2. Example: url::base() instead of base_url()
  3. Example: form::open() instead of form_open()
  4. The default helpers are available in system/helpers

If you have custom helpers they need to be changed. Assuming your helper file is foo.php:

  1. wrap all the functions in the file in class foo { }
  2. prepend public static in front of all the function names

Calls are now made via foo::function().

Note also that the CodeIgniter helpers and libraries typically have this line at the top of the script:

<?php if (!defined('BASEPATH')) exit('No direct script access allowed');

This is not valid for Kohana so if you have copied this line for your own helpers etc you need to change it to the following to work in Kohana:

<?php defined('SYSPATH') or die('No direct access allowed.');


Views are now treated somewhat differently. Instead of being “flat” files, views are now objects. This allows much greater flexibility, and easier “view-in-view” handling.

// Load the view and set the $title variable
$view = new View('template', array('title' => 'User Details'));
// Sets the $username variable in the view
$view->username = 'JohnDoe';
// Sets the $visits variable to another view
$view->visits = new View('user/visits', array('user_id' => 3));
// Renders the view to a string
$str_view = $view->render();
// Displays the view

Note: Using print or echo on a View will cause it to render into a string. This is very useful in Views:

<!-- This example is the "template" view from above -->
<h1><?php echo $title ?> for <?php echo $username ?></h1>
<div id="visits"><?php echo $visits ?></div>

In the above example, a View object, $visits, was used as a string. This syntax is encouraged because it is very short and readable when mixed with HTML.


There is a important note, in CI you can use the $this in the model and you have the same libraries as your controller, in kohana only the db library is loaded on a model. If you need more libraries you have two options:

// Create a new object with the library
$uri = new Uri;
$value = $uri->segment(3);
// Can not use $this->uri->segment(3) as used in CI
// Use the instance of your controller
$value = Kohana::instance()->uri->segment(3);
installation/migration.txt · Last modified: 2009/03/12 00:01 by anaxamaxan