I tried CodeIgniter. While I like it. I also decided to try the Teaching, because I had heard so much about ORM, and this Doctrine is beautiful. I found a few lessons:
I tried all the methods that I found with them to try to set up a working Doctrine installation, but I still cannot load my model. One common thread in all of these documents is that they are old and refer to older versions of Doctrine and / or CI, even Doctrine, corresponding to the docs version 0.11 documentation. I am using CodeIgniter-1.7.2 and Doctrine-1.2.3.
Does anyone have up-to-date documentation? Can anyone see where the code below goes wrong? This is based on the phpandstuff link.
File Structure
root
\_system
\_application
\_config
\_controllers
\_models
\_views
\_plugins
\_doctrine
\_lib
\_Doctrine.php
\_doctrine_pi.php
System / plugins / doctrine_pi.php
require_once BASEPATH.'/plugins/doctrine/lib/Doctrine.php';
require_once APPPATH.'/config/database.php';
foreach ($db as $connection_name => $db_values) {
$dsn = $db[$connection_name]['dbdriver'] .
'://' . $db[$connection_name]['username'] .
':' . $db[$connection_name]['password'].
'@' . $db[$connection_name]['hostname'] .
'/' . $db[$connection_name]['database'];
Doctrine_Manager::connection($dsn,$connection_name);
}
require_once BASEPATH.'/libraries/Model.php';
spl_autoload_register(array('Doctrine', 'autoload'));
spl_autoload_register(array('Doctrine', 'modelsAutoload'));
$manager = Doctrine_Manager::getInstance();
$manager->setAttribute(Doctrine::ATTR_MODEL_LOADING, Doctrine::MODEL_LOADING_CONSERVATIVE);
$manager->setAttribute(Doctrine::ATTR_AUTOLOAD_TABLE_CLASSES, true);
$manager->setAttribute(Doctrine_Core::ATTR_AUTOLOAD_TABLE_CLASSES, true);
Doctrine::loadModels(APPPATH.'models');
Doctrine_Manager::getInstance()->setAttribute(
Doctrine::ATTR_AUTO_ACCESSOR_OVERRIDE, true);
Doctrine_Manager::getInstance()->setAttribute(
Doctrine::ATTR_DEFAULT_COLUMN_OPTIONS,
array('notnull' => true, 'unsigned' => true));
Doctrine_Manager::getInstance()->setAttribute(
Doctrine::ATTR_DEFAULT_IDENTIFIER_OPTIONS,
array('name' => 'id', 'type' => 'integer', 'length' => 4));
from system /application/config/autoload.php
/*
| -------------------------------------------------------------------
| Auto-load Plugins
| -------------------------------------------------------------------
| Prototype:
|
| $autoload['plugin'] = array('captcha', 'js_calendar');
*/
$autoload['plugin'] = array('doctrine');
root / system / model / User.php
class User extends Doctrine_Record {
function __construct(){
parent::__construct();
}
function setTableDefinition(){
$this->hasDefinition("username", "string", 255);
$this->hasDefinition("password", "string", 255);
}
}
If someone wants to see my controller or something else, let me know. The controller simply echo“added the user” and uses the doctrine to save the user. This is encountered with "Fatal error: User class not found ..."