Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public function _initDoctrine()
- {
- // include and register Doctrine's class loader
- require_once('Doctrine/Common/ClassLoader.php');
- $classLoader = new \Doctrine\Common\ClassLoader(
- 'Doctrine'
- );
- $classLoader->register();
- // create the Doctrine configuration
- $config = new \Doctrine\ORM\Configuration();
- // setting the cache ( to ArrayCache. Take a look at
- // the Doctrine manual for different options ! )
- $cache = new \Doctrine\Common\Cache\ArrayCache;
- $config->setMetadataCacheImpl($cache);
- $config->setQueryCacheImpl($cache);
- // choosing the driver for our database schema
- // we'll use annotations
- $driver = $config->newDefaultAnnotationDriver(
- APPLICATION_PATH . '/modules/default/models'
- );
- $config->setMetadataDriverImpl($driver);
- // set the proxy dir and set some options
- $config->setProxyDir(APPLICATION_PATH . '/modules/default/models/Proxies');
- $config->setAutoGenerateProxyClasses(true);
- $config->setProxyNamespace('App\Proxies');
- // now create the entity manager and use the connection
- // settings we defined in our application.ini
- $connectionSettings = $this->getOption('doctrine');
- $conn = array(
- 'driver' => $connectionSettings['connection']['driver'],
- 'user' => $connectionSettings['connection']['user'],
- 'password' => $connectionSettings['connection']['password'],
- 'dbname' => $connectionSettings['connection']['dbname'],
- 'host' => $connectionSettings['connection']['host']
- );
- $entityManager = \Doctrine\ORM\EntityManager::create($conn, $config);
- // push the entity manager into our registry for later use
- $registry = Zend_Registry::getInstance();
- $registry->entityManager = $entityManager;
- return $entityManager;
- }
Add Comment
Please, Sign In to add comment