Doctrine in Kohana

I’ve been using kohana and its query builder for a while now – its good but in time I came to notice that I begin rewriting code over and over again so I tried to break out of the kohana-database shell and tried out existing ORM frameworks. If you’re curious about ORM check here – http://en.wikipedia.org/wiki/Object-relational_mapping. In short; using orm frameworks may greatly reduce the data-access layer code you write in your application and ensures functionality and ease in retrieving data and treating them as objects.

Without further ado; the integration of kohana and doctrine.

Instructions:
1) Download doctrine module here – http://dl.dropbox.com/u/617821/misty/doctrine.1.2.zip
2) Extract the doctrine folder to your modules directory. eg /public_html/modules/
3) Include doctrine in your modules list located in application/config/config.php
$config['modules'] = array
(
MODPATH.'doctrine',        // Doctrine
// MODPATH.'archive',    // Archive utility
// MODPATH.'payment',   // Online payments
// MODPATH.'unit_test',    // Unit testing
);

4) Make sure you enable hooks for your particular application in application/config/config.php
$config['enable_hooks'] = TRUE;
5) Before running your application, create these configuration folders (be sure to set permissions to 777), doctrine will import and export doctrine-specific configurations here:
application/config/doctrine/sql
application/config/doctrine/fixtures
application/config/doctrine/migrations
application/config/doctrine/schema

6) Before running your application, create these models folders (be sure to set permissions to 777), doctrine will store and load your auto-generated models from here:
application/models/doctrine
application/models/doctrine/generated

7) Test your application. You can generate models from your database schema by executing this code:
Doctrine::generateModelsFromDb(
'application/models/doctrine',
array('doctrine'),
array('generateTableClasses' => false)
);

And that’s pretty much it to make doctrine work with kohana. I’ve tested this configuration both local and online. This configuration uses the application/config/database.php so you don’t have to re-specify the credentials of your database elsewhere in the application.

If it doesn’t work on your end don’t hesitate to let me know. =)

Other Information:
Tested working in: Kohana v2.3.4, PHP v5.2.6, MySQL v5.0.67-community-nt
ORM framework used: Doctrine v1.2

Other References:
http://www.mapledesign.co.uk/code/kohana-doctrine/ – I got most of the idea from here
http://www.doctrine-project.org/documentation/manual/1_2/en/introduction – doctrine documentation / manual
http://www.kohanaphp.com/ – kohana php framework


Comments

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.