Integrating Zend Framework 1.10 with Doctrine 2


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



Copy this code and paste it in your HTML
  1. // Bootstrap.php
  2. function _initDoctrine() {
  3. // setup configuration as seen from the sandbox application
  4. // TODO: read configuration from application.ini
  5. $config = new \Doctrine\ORM\Configuration;
  6. $cache = new \Doctrine\Common\Cache\ArrayCache;
  7. $config->setMetadataCacheImpl($cache);
  8. $driverImpl = $config->newDefaultAnnotationDriver('../Application/Entities');
  9. $config->setMetadataDriverImpl($driverImpl);
  10. $config->setQueryCacheImpl($cache);
  11. $config->setProxyDir('../Application/Proxies');
  12. $config->setProxyNamespace('Application\Proxies');
  13. $config->setAutoGenerateProxyClasses(true);
  14.  
  15. $connectionOptions = array(
  16. 'driver' => 'pdo_mysql',
  17. 'user' => 'root',
  18. 'password' => '',
  19. 'dbname' => 'learningzf'
  20. );
  21.  
  22. // setup entity manager
  23. $em = \Doctrine\ORM\EntityManager::create($connectionOptions, $config);
  24. Zend_Registry::set("em", $em);
  25. return $em;
  26. }
  27.  
  28. // now i can access the entity manager from anywhere thru
  29. $em = Zend_Registry::get('em');
  30.  
  31. // application.ini
  32. // autoloading Doctrine, Symfony & Application namespace classes. my Doctrine entities are found in library/Application/Entities
  33. autoloaderNamespaces[] = Doctrine
  34. autoloaderNamespaces[] = Symfony
  35. autoloaderNamespaces[] = Application

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.