Guest User

Untitled

a guest
Oct 17th, 2017
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.01 KB | None | 0 0
  1.  
  2. public function _initDoctrine()
  3. {
  4. // include and register Doctrine's class loader
  5. require_once('Doctrine/Common/ClassLoader.php');
  6. $classLoader = new \Doctrine\Common\ClassLoader(
  7. 'Doctrine'
  8. );
  9. $classLoader->register();
  10.  
  11. // create the Doctrine configuration
  12. $config = new \Doctrine\ORM\Configuration();
  13.  
  14. // setting the cache ( to ArrayCache. Take a look at
  15. // the Doctrine manual for different options ! )
  16. $cache = new \Doctrine\Common\Cache\ArrayCache;
  17. $config->setMetadataCacheImpl($cache);
  18. $config->setQueryCacheImpl($cache);
  19.  
  20. // choosing the driver for our database schema
  21. // we'll use annotations
  22. $driver = $config->newDefaultAnnotationDriver(
  23. APPLICATION_PATH . '/modules/default/models'
  24. );
  25. $config->setMetadataDriverImpl($driver);
  26.  
  27. // set the proxy dir and set some options
  28. $config->setProxyDir(APPLICATION_PATH . '/modules/default/models/Proxies');
  29. $config->setAutoGenerateProxyClasses(true);
  30. $config->setProxyNamespace('App\Proxies');
  31.  
  32. // now create the entity manager and use the connection
  33. // settings we defined in our application.ini
  34. $connectionSettings = $this->getOption('doctrine');
  35. $conn = array(
  36. 'driver' => $connectionSettings['connection']['driver'],
  37. 'user' => $connectionSettings['connection']['user'],
  38. 'password' => $connectionSettings['connection']['password'],
  39. 'dbname' => $connectionSettings['connection']['dbname'],
  40. 'host' => $connectionSettings['connection']['host']
  41. );
  42. $entityManager = \Doctrine\ORM\EntityManager::create($conn, $config);
  43.  
  44. // push the entity manager into our registry for later use
  45. $registry = Zend_Registry::getInstance();
  46. $registry->entityManager = $entityManager;
  47.  
  48. return $entityManager;
  49. }
Add Comment
Please, Sign In to add comment