This is a wrapper library to Doctrine2. It allows you to use the doctrine
command-line executable, and create Entities for use within CodeIgniter.
Author: Nick Jennings <firstname.lastname@example.org> irc#nkj twitter:@hurphendale
You can place the entire checkout in the application/third_party directory,
or copy the files out and place them in their respective places.
This document will cover using the library from the third_party directory.
1. Move the codeigntier-doctrine2 directory to your application/third_party/
2. Download or checkout the Doctrine 2 libraries and place them in the
codeigniter-doctrine2/libraries/ directory as the Doctrine dir.
So you should have:
NOTE: If you are cloning from github, keep in mind doctrine keeps these
libraries separated, so you will need to check out each one
individually and copy them into the Doctrine directory.
3. Check the codeigntier-doctrine2/config/doctrine.php and make any changes
that you require. It needs to know where your database.php file lives, so
that it can establish DB connections.
Using the default configuration, Doctrine will expect to find:
...application/models/Proxies (must be write-able by the webserver)
4. It helps to symlink to the config from the application/config/ directory
so that you can load the config before you have loaded the library (ie.
so to get the location for add_package_path).
$ cd application/config/
$ ln -s ../third_party/codeigniter-doctrine2/config/doctrine.php
5. To set up the doctrine executable, what I do is create a 'bin' directory
in the base dir and symlink to the doctrine executable. For example:
$ mkdir bin
$ cd bin/
$ ln -s ../application/third_party/codeigntier-doctrine2/bin/doctrine
$ cd ..
$ php bin/doctrine
(you should see the doctrine command-line help output)
The namespace 'Entity' will look in models/Entity/
See EXAMPLE file for an example Entity/User.php class
NOTE: Currently, this library has only been tested using the Annotations
driver. Though you should be able to modify the
libraries/Doctrine.php to use YAML or XML mappings if you prefer.
From within your controller you can first initialize the config file, then
use the config param 'package_path' to load the library:
You can now access the entity manager with:
$user = $this->em->find('Entity\User', $user_id);