Doctrine2 wrapper for CodeIgniter2 - Development config.


/ Published in: PHP
Save to your folder(s)



Copy this code and paste it in your HTML
  1. <?php
  2. use Doctrine\Common\ClassLoader,
  3. Doctrine\ORM\Configuration,
  4. Doctrine\ORM\EntityManager,
  5. Doctrine\Common\Cache\ArrayCache,
  6. Doctrine\DBAL\Logging\EchoSQLLogger;
  7.  
  8. class Doctrine {
  9.  
  10. public $em = null;
  11.  
  12. public function __construct()
  13. {
  14. // load database configuration from CodeIgniter
  15. require_once APPPATH.'config/database.php';
  16.  
  17. // Set up class loading. You could use different autoloaders, provided by your favorite framework,
  18. // if you want to.
  19. require_once APPPATH.'libraries/Doctrine/Common/ClassLoader.php';
  20.  
  21. $doctrineClassLoader = new ClassLoader('Doctrine', APPPATH.'libraries');
  22. $doctrineClassLoader->register();
  23. $entitiesClassLoader = new ClassLoader('models', rtrim(APPPATH, "/" ));
  24. $entitiesClassLoader->register();
  25. $proxiesClassLoader = new ClassLoader('Proxies', APPPATH.'models/proxies');
  26. $proxiesClassLoader->register();
  27.  
  28. // Set up caches
  29. $config = new Configuration;
  30. $cache = new ArrayCache;
  31. $config->setMetadataCacheImpl($cache);
  32. $driverImpl = $config->newDefaultAnnotationDriver(array(APPPATH.'models/Entities'));
  33. $config->setMetadataDriverImpl($driverImpl);
  34. $config->setQueryCacheImpl($cache);
  35.  
  36. $config->setQueryCacheImpl($cache);
  37.  
  38. // Proxy configuration
  39. $config->setProxyDir(APPPATH.'/models/proxies');
  40. $config->setProxyNamespace('Proxies');
  41.  
  42. // Set up logger
  43. $logger = new EchoSQLLogger;
  44. $config->setSQLLogger($logger);
  45.  
  46. $config->setAutoGenerateProxyClasses( TRUE );
  47.  
  48. // Database connection information
  49. $connectionOptions = array(
  50. 'driver' => 'pdo_mysql',
  51. 'user' => $db['default']['username'],
  52. 'password' => $db['default']['password'],
  53. 'host' => $db['default']['hostname'],
  54. 'dbname' => $db['default']['database']
  55. );
  56.  
  57. // Create EntityManager
  58. $this->em = EntityManager::create($connectionOptions, $config);
  59. }
  60. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.