Return to Snippet

Revision: 29347
at July 27, 2010 20:42 by jiewmeng


Initial Code
// Bootstrap.php
function _initDoctrine() {
	// setup configuration as seen from the sandbox application
	// TODO: read configuration from application.ini
	$config = new \Doctrine\ORM\Configuration;
	$cache = new \Doctrine\Common\Cache\ArrayCache;
	$config->setMetadataCacheImpl($cache);
	$driverImpl = $config->newDefaultAnnotationDriver('../Application/Entities');
	$config->setMetadataDriverImpl($driverImpl);
	$config->setQueryCacheImpl($cache);
	$config->setProxyDir('../Application/Proxies');
	$config->setProxyNamespace('Application\Proxies');
	$config->setAutoGenerateProxyClasses(true);

	$connectionOptions = array(
	  'driver' => 'pdo_mysql',
	  'user' => 'root',
	  'password' => '',
	  'dbname' => 'learningzf'
	);

	// setup entity manager
	$em = \Doctrine\ORM\EntityManager::create($connectionOptions, $config);
	Zend_Registry::set("em", $em);
	return $em;
}

// now i can access the entity manager from anywhere thru 
$em = Zend_Registry::get('em');

// application.ini
// autoloading Doctrine, Symfony & Application namespace classes. my Doctrine entities are found in library/Application/Entities
autoloaderNamespaces[] = Doctrine
autoloaderNamespaces[] = Symfony
autoloaderNamespaces[] = Application

Initial URL

                                

Initial Description

                                

Initial Title
Integrating Zend Framework 1.10 with Doctrine 2

Initial Tags

                                

Initial Language
PHP