Kohana Doctrine integration - an alternative to the Kohana ORM

Tired of the limitations of Kohana's ORM? Want a proven, full-featured ORM to use in your Kohana projects? This module allows the Doctrine ORM to be used with Kohana.

Download

Download 0.3 (Kohana 2.2+)

Download 0.2 (Kohana 2.1)

Install

This module comes with a sample database schema so you can test tables are generated. If you want to write all your own code, replace the contents of application/config/doctrine/schema/database.yml with your schema, and delete application/controllers/doctrine.php

  1. Extract the file you've downloaded
  2. Copy it over the top of your Kohana installation.
  3. You now need to install Doctrine. It needs to go in the modules/doctrine/vendor folder. Please see their instructions for getting Doctrine - I manage my Kohana projects using SVN and so use the svn:externals method. If you want to do it my way:
    • Delete the vendor folder
    • edit the SVN properties on modules/doctrine and set svn:externals to vendor http://svn.phpdoctrine.org/branches/0.11/lib
    • Run a svn update
    You will end up with a file modules/doctrine/vendor/Doctrine.php and a directory containing lots of files at modules/doctrine/vendor/Doctrine/
  4. If running on Unix or Linux, set modules/doctrine/doctrine to be executable (755)
  5. Open application/config/config.php and add a line to $config['modules'] to load the doctrine module:
    $config['modules'] = array
    (
        MODPATH.'doctrine',
    	// Your existing modules listed here
    );
  6. Also in config.php, look for the line
    $config['enable_hooks'] = FALSE;
    and change it to
    $config['enable_hooks'] = TRUE;
    modules/doctrine/hooks/doctrine.php
  7. Create your schema in application/config/doctrine/schema
  8. Open a command window and go to modules/doctrine. Run the doctrine command from the prompt:
    > doctrine
    or on Windows
    > C:\path\to\php.exe doctrine
    And choose the command you want.

Support

Sorry, but I can't answer questions about using Doctrine. Please read the Doctrine manual or ask on the phpdoctrine mailing list. Alternatively we offer consulting services.

If you encounter problems getting the integration to work or receive error messages from Kohana, please let me know.

FAQ

Q: Why does adding doctrine put folders in application/ as well as modules/?

This is something I thought about deeply before deciding to do it. As I see it, a module is self-contained code which should be independent of the current application. In the case of doctrine, this is the library, hook, and command-line interface.

The schema files, models and fixtures are application specific, therefore reside in the application directory.

This means that the module can be copied from one Kohana installation to another can not carry any application specific data with it. It does however mean the folders in application/config/doctrine have to be recreated each time.

I did post in the Kohana Forum before starting to see if my understanding of the separation between application and modules was correct but didn't receive much helpful feedback

Q: Why do you not include doctrine with this module?

Doctrine is under heavy development, and if I included it with this module it would always be out of date. Not including doctrine allows you to use a SVN checkout without having to delete doctrine first. The best way to get Doctrine is to download it directly from http://phpdoctrine.org. This way you will always get the latest version.

I use a SVN checkout of Doctrine (pinned to the 0.10 branch) so I get bug fixes whenever they're made, and I recommend you do the same.

Q: Why are models put in application/models/doctrine not application/models?

Good question! I don't like them in a sub-directory, however if doctrine models went in the same directory as the Kohana models the command-line tools wouldn't work, as they expect to load and inspect all models when generating the SQL.