Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- use Doctrine\Common\ClassLoader,
- Doctrine\ORM\Tools\Setup,
- Doctrine\ORM\EntityManager;
- class Doctrine
- {
- public $em;
- public function __construct()
- {
- require_once __DIR__ . '/Doctrine/ORM/Tools/Setup.php';
- Setup::registerAutoloadDirectory(__DIR__);
- // Load the database configuration from CodeIgniter
- require APPPATH . 'config/database.php';
- $connection_options = array(
- 'driver' => 'pdo_mysql',
- 'user' => $db['default']['username'],
- 'password' => $db['default']['password'],
- 'host' => $db['default']['hostname'],
- 'dbname' => $db['default']['database'],
- 'charset' => $db['default']['char_set'],
- 'driverOptions' => array(
- 1002 =>'SET NAMES utf8'
- ),
- );
- // With this configuration, your model files need to be in application/models/Entity
- // e.g. Creating a new Entity\User loads the class from application/models/Entity/User.php
- $models_namespace = 'Entity';
- $models_path = APPPATH . 'models';
- $proxies_dir = APPPATH . 'models/Proxies';
- $metadata_paths = array(APPPATH . 'models');
- // Set $dev_mode to TRUE to disable caching while you develop
- $config = Setup::createAnnotationMetadataConfiguration($metadata_paths, $dev_mode = true, $proxies_dir);
- $this->em = EntityManager::create($connection_options, $config);
- $loader = new ClassLoader($models_namespace, $models_path);
- $loader->register();
- }
- }
- /*
- use Doctrine\Common\ClassLoader,
- Doctrine\ORM\Configuration,
- Doctrine\ORM\EntityManager,
- Doctrine\Common\Cache\ArrayCache,
- Doctrine\DBAL\Logging\EchoSQLLogger;
- class Doctrine {
- public $em = null;
- public function __construct()
- {
- // load database configuration from CodeIgniter
- require_once APPPATH.'config/database.php';
- // Set up class loading. You could use different autoloaders, provided by your favorite framework,
- // if you want to.
- require_once APPPATH.'libraries/Doctrine/Common/ClassLoader.php';
- $doctrineClassLoader = new ClassLoader('Doctrine', APPPATH.'libraries');
- $doctrineClassLoader->register();
- $entitiesClassLoader = new ClassLoader('models', rtrim(APPPATH, "/" ));
- $entitiesClassLoader->register();
- $proxiesClassLoader = new ClassLoader('Proxies', APPPATH.'models/proxies');
- $proxiesClassLoader->register();
- // Set up caches
- $config = new Configuration;
- $cache = new ArrayCache;
- $config->setMetadataCacheImpl($cache);
- $driverImpl = $config->newDefaultAnnotationDriver(array(APPPATH.'models/Entities'));
- $config->setMetadataDriverImpl($driverImpl);
- $config->setQueryCacheImpl($cache);
- $config->setQueryCacheImpl($cache);
- // Proxy configuration
- $config->setProxyDir(APPPATH.'/models/proxies');
- $config->setProxyNamespace('Proxies');
- // Set up logger
- $logger = new EchoSQLLogger;
- $config->setSQLLogger($logger);
- $config->setAutoGenerateProxyClasses( TRUE );
- // Database connection information
- $connectionOptions = array(
- 'driver' => 'pdo_mysql',
- 'user' => $db['default']['username'],
- 'password' => $db['default']['password'],
- 'host' => $db['default']['hostname'],
- 'dbname' => $db['default']['database']
- );
- // Create EntityManager
- $this->em = EntityManager::create($connectionOptions, $config);
- }
- }
- */
Advertisement
Add Comment
Please, Sign In to add comment