Unable to load models into CodeIgniter using Doctrine

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   

// load Doctrine library
require_once BASEPATH.'/plugins/doctrine/lib/Doctrine.php';

// load database configuration from CodeIgniter
require_once APPPATH.'/config/database.php';

// this will allow Doctrine to load Model classes automatically

//below is the suggested method of loading models
//I also tried a user suggestion of "modelsAutoload"
//spl_autoload_register(array('Doctrine', 'autoload'));
//spl_autoload_register(array('Doctrine_Core', 'modelsAutoload'));

// we load our database connections into Doctrine_Manager
// this loop allows us to use multiple connections later on
foreach ($db as $connection_name => $db_values) {

    // first we must convert to dsn format
    $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);
}

// CodeIgniter Model class needs to be loaded
require_once BASEPATH.'/libraries/Model.php';

// telling Doctrine where our models are located
//Below is another user suggestion, this also fails
//within my setup.
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');


// (OPTIONAL) CONFIGURATION BELOW

// this will allow us to use "mutators"
Doctrine_Manager::getInstance()->setAttribute(
    Doctrine::ATTR_AUTO_ACCESSOR_OVERRIDE, true);

// this sets all table columns to notnull and unsigned (for ints) by default
Doctrine_Manager::getInstance()->setAttribute(
    Doctrine::ATTR_DEFAULT_COLUMN_OPTIONS,
    array('notnull' => true, 'unsigned' => true));

// set the default primary key to be named 'id', integer, 4 bytes
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 ..."

+3
source share
2 answers

I followed the tutorial here :: http://www.scribd.com/Ci-Doctrine/d/43303007

, Windows, APPPATH , , - C:\wamp\www\v1/system/application/. $system_folder index.php .

+1

. Zend Framework, CI .

try {
    Doctrine_Manager::getInstance()->setAttribute(Doctrine::ATTR_MODEL_LOADING, Doctrine::MODEL_LOADING_AGGRESSIVE);
    Doctrine_Manager::getInstance()->setAttribute(Doctrine::ATTR_VALIDATE, Doctrine::VALIDATE_ALL);
    $conn = Doctrine_Manager::connection($this->_db->getConnection());
    Doctrine::loadModels($this->_root . '/application/models');
} catch (Zend_Db_Adapter_Exception $e) {
    echo 'Incorrect database login: ' . $e->getMessage();
}

, . , .

0

Source: https://habr.com/ru/post/1767697/


All Articles