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 – 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.

1) Download doctrine module here –
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:

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:

7) Test your application. You can generate models from your database schema by executing this code:
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: – I got most of the idea from here – doctrine documentation / manual – kohana php framework


Leave a Reply

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