CodeIgniter2的Doctrine2包装器-开发配置。

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了CodeIgniter2的Doctrine2包装器-开发配置。相关的知识,希望对你有一定的参考价值。

  1. <?php
  2. use DoctrineCommonClassLoader,
  3. DoctrineORMConfiguration,
  4. DoctrineORMEntityManager,
  5. DoctrineCommonCacheArrayCache,
  6. DoctrineDBALLoggingEchoSQLLogger;
  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. }

以上是关于CodeIgniter2的Doctrine2包装器-开发配置。的主要内容,如果未能解决你的问题,请参考以下文章

Codeigniter2,Doctrine2,作曲家等。一个巨大的混乱

CodeIgniter2的Doctrine2 CLI

PHP cli-config.php - doctrine2 + codeigniter2

在 Doctrine 2 / CodeIgniter 2 中找不到实体模型

将 Codeigniter 2 与 Doctrine ORM 2 < PHP v5.2 一起使用

使用Doctrine2加入表中的鉴别器