Hey! Keep up to date with the project through its beta and public launch by following @getsparks.

2,941 Installs

Basic Information: doctrine2

Easily add Doctrine2 ORM horsepower to your ignited code!

Contributor : stickgrinder
Email : Log in to view
Author Website : http://www.agavee.com
Spark Website : https://github.com/stickgrinder/doctrine2-spark
Repository Type : git
Number of Installs : 2,941

Get the Latest

  • 1.0.0 Pushed April 20th, 2011
    php tools/spark install -v1.0.0 doctrine2 Or download this version manually: Get doctrine2-v1.0.zip


This Spark seamlessly integrates Doctrine2 ORM in CI2. Doctrine2 is a powerful ORM based on DataMapper pattern, providing database abstraction, entities-based ORM complete with an entity manager, and a powerful command line tool to automate many tasks. This spark contains both Doctrine2 library and the CLI tool, but to make it work you'll have to copy some files by hand.

Installation and configuration

After installing this Spark, create a directory called proxies inside your application/models folder and make it writable:

$ cd /path/to/your/ci2/installation
$ mkdir ./application/models/proxies
$ chmod a+w ./application/models/proxies

You could use this Spark as any other, by loading it in your controller:


// entity manager is loaded

To make access to entity manager more comfortable, use this:

$this->em = $this->doctrine2->em;

// your Entity Manager is now quickly available

To enable CLI tool, follow these instructions:

  • Copy tools folder from Spark directory to your CI2 installation path (if you're using Sparks you should already have a tools directory in your installation path):

    $ cd /path/to/your/ci2/installation $ cp ./sparks/doctrine2//tools . -R

  • Use the CLI tool from your tools directory:

    $ tools/doctrine COMMAND PARAMS

Remember that your model entities will have to be placed in application/models directory, while generated proxies will be put in application/models/proxies directory.

Known bugs and roadmap

There is no known bugs so far, but some feature is missing from a "standard" application/libraries-based installation.

  • Autoloading of Doctrine library doesn't works out of the box. You should manually load the spark every time you need it. You could always do this in your controller constructor, so that you avoid too much code duplication.
  • You could think about implementing MYController to extend standard controller and load the Entity Manager in all of the controllers without explicitly loading the spark; I tried but this doesn't work, since MYLoader (that is how sparks extends CI loading mechanism) is loaded after MY_Controller, so $this->load->spark() is unavailable at this stage. I also tried with a post_controller_constructor hook but: 1) something didn't work and 2) this is an awful workaround and the right way is to getting sparks autoloading functionality to work as intended. This will therefore be addressed in a future release.
  • I'd like to have the Entity Manager automatically available in all controllers via $this->em if Doctrine2 spark is autoloaded, but I'll have to solve previous point, obviously.

If you could find solutions to above problems, please contact me or send a pull request on GitHub project page: https://github.com/stickgrinder/doctrine2-spark

Resources and further readings:

Contacts and footnotes

This Spark has been "sponsored" by Agavee Team, written by Paolo Pustorino (hey, that's me! :) follow @stickgrinder tweets) and it's hosted on GitHub.

Thanks to Joseph Wynn for his clear tutorial, and thanks to all that will find (and fix!) bugs, send me nice twits and offer me some beer&pizza! :)

Older Versions

  • There are no older versions.


blog comments powered by Disqus