/ Published in: PHP
an alternative to a previous method i did using Zend Framework's autoloaders only. this method uses Doctrine's autoloaders for doctrine's classes and Zend's for Zend's :)
i think the difficulty i had was autoloading from a specific directory (with just Zend's autoloaders). eg. in Doctrine autoloaders i will do
new Doctrine\Common\ClassLoader(
'Application\Models',
APPLICATION_PATH . '/models'
);
where the 2nd param is the path to find the classes. basically,
- we create a resource method in `bootstrap.php`.
- in it, we setup doctrine in a similar way to how the doctrine sandbox sets it up. to setup autoloading of doctrine's classes, as we create new doctrine class loaders, we push them into the zend's autoloader.
- then its basically the same as the sandbox app, setting up caches, metadata drivers, proxies etc.
i think the difficulty i had was autoloading from a specific directory (with just Zend's autoloaders). eg. in Doctrine autoloaders i will do
new Doctrine\Common\ClassLoader(
'Application\Models',
APPLICATION_PATH . '/models'
);
where the 2nd param is the path to find the classes. basically,
- we create a resource method in `bootstrap.php`.
- in it, we setup doctrine in a similar way to how the doctrine sandbox sets it up. to setup autoloading of doctrine's classes, as we create new doctrine class loaders, we push them into the zend's autoloader.
- then its basically the same as the sandbox app, setting up caches, metadata drivers, proxies etc.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
function _initDoctrine() { // setup Zend & Doctrine Autoloaders require_once "Doctrine/Common/ClassLoader.php"; $zendAutoloader = Zend_Loader_Autoloader::getInstance(); // $autoloader = array(new \Doctrine\Common\ClassLoader(), 'loadClass'); $zendAutoloader->pushAutoloader($autoloader, 'Symfony\\'); $zendAutoloader->pushAutoloader($autoloader, 'Doctrine\\'); $zendAutoloader->pushAutoloader($autoloader, 'DoctrineExtensions\\'); $zendAutoloader->pushAutoloader($autoloader, 'Application\\Models\\'); $zendAutoloader->pushAutoloader($autoloader, 'Application\\Proxies'); $zendAutoloader->pushAutoloader($autoloader, 'DoctrineExtensions\\'); // 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); $config->setMetadataDriverImpl($driverImpl); $config->setQueryCacheImpl($cache); $config->setProxyNamespace('Application\\Proxies'); $config->setAutoGenerateProxyClasses(true); '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; }