^Status|First Draft|
^Todo|Requires more development|
====== Migration ======
Users of Kohana version 1.x ("Blueflame") or CodeIgniter 1.x migrating to Kohana 2.0 can follow these steps to migrate their application.
===== Installation =====
Starting with a fresh Kohana install, delete ''application'' folder, and copy your existing application folder to the same location.
===== Configuration =====
Remove your old ''config'' folder.
- Copy the ''application/config'' directory from Kohana 2.x to ''application/config''
- Edit ''application/config/config.php'', the main configuration files for your application
- Review the [[general:configuration|User Guide: Configuration]] page
===== Logging =====
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:
- ''%%function __construct()%%'' instead of ''function Page()''
- ''%%parent::__construct()%%'' instead of ''parent::Controller()''
- **Note:** This also applies to Models!
Rename all your models to ''{NAME}_Model''
- For example, if your old model was ''PageModel'', make it ''Page_Model''
- Change all your model loads to just model name: ''$this->load->model('page')''
- If you add a ''%%__construct()%%'' function, be sure to call ''%%parent::__construct()%%''
===== Libraries =====
==== Base Controllers ====
If you have a base controller for your application (in the libraries folder) you will need to:
- Change the ''MY_Controller extends Controller'' to ''Controller extends Controller_Core''
- Change references to ''MY_Controller'' in your controllers to ''Controller''
- Use the PHP5 syntax for the constructor in your base controller
==== URI ====
The CI function ''uri_to_assoc($offset)'' becomes ''segment_array($offset,$associative)'' with ''$associative'' set to ''TRUE''.
==== Other ====
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.
===== Helpers =====
Change all your helper calls to the new syntax: ''helper::function()''
- Example: ''html::anchor()'' instead of ''anchor()''
- Example: ''url::base()'' instead of ''base_url()''
- Example: ''form::open()'' instead of ''form_open()''
- 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'':
- wrap all the functions in the file in ''class foo { }''
- 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:
''
// 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
$view->render(TRUE);
**Note:** Using ''print'' or ''echo'' on a View will cause it to render into a string. This is very useful in Views:
for
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.
===== Models =====
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);