-
Notifications
You must be signed in to change notification settings - Fork 26
Using Doctrine with Code Igniter
[h3]Download Doctrine[/h3]
First we must get the source of Doctrine from svn and place it in the system/database folder.
[code] $ cd system/database $ svn co http://svn.phpdoctrine.org/branches/0.9/lib doctrine $ cd ..
// If you use svn in your project you can set Doctrine as an external so you receive bug fixes automatically from svn $ svn propedit svn:externals database
// In your favorite editor add the following line // doctrine http://svn.phpdoctrine.org/branches/0.9/lib [/code]
[h3]Setup Doctrine[/h3]
Now we must setup the configuration for Doctrine and load it in system/application/config/database.php
[code] $ vi application/config/database.php [/code]
The code below needs to be added under this line of code
[code] $db['default']['cachedir'] = ""; [/code]
Add this code [code] // Create dsn from the info above $db['default']['dsn'] = $db['default']['dbdriver'] . '://' . $db['default']['username'] . ':' . $db['default']['password']. '@' . $db['default']['hostname'] . '/' . $db['default']['database'];
// Require Doctrine.php require_once(realpath(dirname(FILE) . '/../..') . DIRECTORY_SEPARATOR . 'database/doctrine/Doctrine.php');
// Set the autoloader spl_autoload_register(array('Doctrine', 'autoload'));
// Load the Doctrine connection Doctrine_Manager::connection($db['default']['dsn'], $db['default']['database']);
// Load the models for the autoloader Doctrine::loadModels(realpath(dirname(FILE) . '/..') . DIRECTORY_SEPARATOR . 'models'); [/code]
Now we must make sure system/application/config/database.php is included in your front controller. Open your front controller in your favorite text editor.
[code] $ cd .. $ vi index.php [/code]
Change the last 2 lines of code of index.php with the following
[code] require_once APPPATH.'config/database.php'; require_once BASEPATH.'codeigniter/CodeIgniter'.EXT; ?> [/code]
[co