8
What is the best way to install Doctrine via commiserate in the codeigniter 3.0? I plan to leave the files in the folder libraries
.
I created the file composer.json
:
{
"config": {
"vendor-dir": "application/libraries"
},
"require": {
"doctrine/common": "2.4.*",
"doctrine/dbal": "2.4.*",
"doctrine/orm": "2.4.*"
}
}
I executed the command php composer.phar install
, creating the files inside the folder application/libraries
in Codeigniter 3.0.
I created a library called Doctrine.php
and added to the autoload
:
$autoload['libraries'] = array('doctrine');
The doctrine.php
:
<?php
//AutoLoader do Composer
$loader = require __DIR__.'/vendor/autoload.php';
//vamos adicionar nossas classes ao AutoLoader
$loader->add('Pasta_library', __DIR__);
use Doctrine\ORM\Tools\Setup;
use Doctrine\ORM\EntityManager;
use Doctrine\ORM\Mapping\Driver\AnnotationDriver;
use Doctrine\Common\Annotations\AnnotationReader;
use Doctrine\Common\Annotations\AnnotationRegistry;
//se for falso usa o APC como cache, se for true usa cache em arrays
$isDevMode = false;
//caminho das entidades
$paths = array(__DIR__ );
// configurações do banco de dados
$dbParams = array(
'driver' => 'pdo_mysql',
'user' => 'root',
'password' => '',
'dbname' => 'dnp',
);
$config = Setup::createConfiguration($isDevMode);
//leitor das annotations das entidades
$driver = new AnnotationDriver(new AnnotationReader(), $paths);
$config->setMetadataDriverImpl($driver);
//registra as annotations do Doctrine
AnnotationRegistry::registerFile(
__DIR__ . '/vendor/doctrine/orm/lib/Doctrine/ORM/Mapping/Driver/DoctrineAnnotations.php'
);
//cria o entityManager
$entityManager = EntityManager::create($dbParams, $config);
When trying to upload the project, the error messages appear:
Fatal error: require(): Failed Opening required '/Users/israel/Sites/agemed/application/Libraries/vendor/autoload.php' (include_path='.:/usr/local/php5/lib/php') in /Users/israel/Sites/agemed/application/Libraries/Doctrine.php on line 3
Showing that the system is not locating the correct path.
Where to correct?
Doctrine.php is in which project folder ?
– Otto