Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- A copier dans "library/LeNomDeTaBibliothèque/Application/Resource" :
- <?php
- require_once('Doctrine/Common/ClassLoader.php');
- /*
- * Interface Doctrine 2.1 avec Zend Framework
- */
- class Evpatoria_Application_Resource_Doctrine extends Zend_Application_Resource_ResourceAbstract
- {
- //
- // Initialise la ressource personnalisée
- //
- public function init()
- {
- return $this->getDoctrine();
- }
- //
- // Récupère un manager d'entités Doctrine correctement initialisé
- //
- public function getDoctrine()
- {
- $options = $this->getOptions();
- // Doctrine
- $classLoader = new \Doctrine\Common\ClassLoader('Doctrine');
- $classLoader->register();
- $config = new \Doctrine\ORM\Configuration();
- // Définition du cache
- $cache = new \Doctrine\Common\Cache\ArrayCache;
- $config->setMetadataCacheImpl($cache);
- $config->setQueryCacheImpl($cache);
- // Chemins
- $driverImpl = $config->newDefaultAnnotationDriver($options['entityDir']);
- $config->setMetadataDriverImpl($driverImpl);
- $config->setProxyDir($options['proxyDir']);
- $config->setProxyNamespace($options['proxyNamespace']);
- $config->setAutoGenerateProxyClasses($options['autoGenerateProxyClasses']);
- // Définition des paramètres de connexion
- $connection = array();
- foreach($options['connection'] as $key => $value)
- $connection[$key] = $value;
- $entityManager = \Doctrine\ORM\EntityManager::create($connection, $config);
- $entityManager->getEventManager()
- ->addEventSubscriber(new \Doctrine\DBAL\Event\Listeners\MysqlSessionInit('utf8'));
- Zend_Registry::set('entityManager', $entityManager);
- return $entityManager;
- }
- }
- A ajouter dans ton fichier de config :
- doctrine:
- entityDir: APPLICATION_PATH/models
- proxyDir: APPLICATION_PATH/models/proxies
- proxyNamespace: Proxy
- autoGenerateProxyClasses: true
- connection:
- driver: pdo_mysql
- host: localhost
- dbname: test
- user: root
- password: monMotdePasse
Add Comment
Please, Sign In to add comment