Guest User

Untitled

a guest
Jan 24th, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.35 KB | None | 0 0
  1. A copier dans "library/LeNomDeTaBibliothèque/Application/Resource" :
  2.  
  3. <?php
  4.  
  5. require_once('Doctrine/Common/ClassLoader.php');
  6.  
  7. /*
  8. * Interface Doctrine 2.1 avec Zend Framework
  9. */
  10. class Evpatoria_Application_Resource_Doctrine extends Zend_Application_Resource_ResourceAbstract
  11. {
  12. //
  13. // Initialise la ressource personnalisée
  14. //
  15. public function init()
  16. {
  17. return $this->getDoctrine();
  18. }
  19.  
  20. //
  21. // Récupère un manager d'entités Doctrine correctement initialisé
  22. //
  23. public function getDoctrine()
  24. {
  25. $options = $this->getOptions();
  26.  
  27. // Doctrine
  28. $classLoader = new \Doctrine\Common\ClassLoader('Doctrine');
  29. $classLoader->register();
  30.  
  31. $config = new \Doctrine\ORM\Configuration();
  32.  
  33. // Définition du cache
  34. $cache = new \Doctrine\Common\Cache\ArrayCache;
  35. $config->setMetadataCacheImpl($cache);
  36. $config->setQueryCacheImpl($cache);
  37.  
  38. // Chemins
  39. $driverImpl = $config->newDefaultAnnotationDriver($options['entityDir']);
  40. $config->setMetadataDriverImpl($driverImpl);
  41. $config->setProxyDir($options['proxyDir']);
  42. $config->setProxyNamespace($options['proxyNamespace']);
  43. $config->setAutoGenerateProxyClasses($options['autoGenerateProxyClasses']);
  44.  
  45. // Définition des paramètres de connexion
  46. $connection = array();
  47. foreach($options['connection'] as $key => $value)
  48. $connection[$key] = $value;
  49.  
  50. $entityManager = \Doctrine\ORM\EntityManager::create($connection, $config);
  51. $entityManager->getEventManager()
  52. ->addEventSubscriber(new \Doctrine\DBAL\Event\Listeners\MysqlSessionInit('utf8'));
  53.  
  54. Zend_Registry::set('entityManager', $entityManager);
  55.  
  56. return $entityManager;
  57. }
  58. }
  59.  
  60.  
  61.  
  62.  
  63. A ajouter dans ton fichier de config :
  64.  
  65. doctrine:
  66. entityDir: APPLICATION_PATH/models
  67. proxyDir: APPLICATION_PATH/models/proxies
  68. proxyNamespace: Proxy
  69. autoGenerateProxyClasses: true
  70. connection:
  71. driver: pdo_mysql
  72. host: localhost
  73. dbname: test
  74. user: root
  75. password: monMotdePasse
Add Comment
Please, Sign In to add comment