/ Published in: PHP
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
<?php use Doctrine\Common\ClassLoader, Doctrine\ORM\Configuration, Doctrine\ORM\EntityManager, Doctrine\Common\Cache\ArrayCache, Doctrine\DBAL\Logging\EchoSqlLogger; require_once __DIR__ . '/config/database.php'; require_once BASEPATH . 'core/Model.php'; require_once __DIR__ . '/libraries/Doctrine/Common/ClassLoader.php'; $doctrineClassLoader = new ClassLoader('Doctrine', __DIR__.'/libraries'); $doctrineClassLoader->register(); $entitiesClassLoader = new ClassLoader('models', __DIR__); $entitiesClassLoader->register(); $proxiesClassLoader = new ClassLoader('Proxies', __DIR__.'/models/proxies'); $proxiesClassLoader->register(); $config = new \Doctrine\ORM\Configuration(); $config->setMetadataCacheImpl(new \Doctrine\Common\Cache\ArrayCache); $config->setProxyDir(__DIR__ . '/Proxies'); $config->setProxyNamespace('Proxies'); $cache = new ArrayCache; // Set up driver $Doctrine_AnnotationReader = new \Doctrine\Common\Annotations\AnnotationReader($cache); $Doctrine_AnnotationReader->setDefaultAnnotationNamespace('Doctrine\ORM\Mapping\\'); $driver = new \Doctrine\ORM\Mapping\Driver\AnnotationDriver($Doctrine_AnnotationReader, realpath('../models')); $config->setMetadataDriverImpl($driver); // Database connection information 'driver' => 'pdo_mysql', 'user' => $db['default']['username'], 'password' => $db['default']['password'], 'host' => $db['default']['hostname'], 'dbname' => $db['default']['database'] ); $em = \Doctrine\ORM\EntityManager::create($connectionOptions, $config); 'db' => new \Doctrine\DBAL\Tools\Console\Helper\ConnectionHelper($em->getConnection()), 'em' => new \Doctrine\ORM\Tools\Console\Helper\EntityManagerHelper($em) ));