我在项目中使用Zend Framework和Doctrine 2。一切正常,但自动加载器不会从Doctrine存储库加载Zend类。
这是Zend自动加载器的引导部分:
/**
* Register namespace Default_
* @return Zend_Application_Module_Autoloader
*/
protected function _initAutoload() {
$autoloader = new Zend_Application_Module_Autoloader(array(
'namespace' => 'Default_',
'basePath' => dirname(__FILE__),
));
return $autoloader;
}
这是我的Doctrine初始化的引导部分:
/**
* Initialize Doctrine
* @return Doctrine_Manager
*/
public function _initDoctrine() {
// include and register Doctrine's class loader
require_once('Doctrine/Common/ClassLoader.php');
$classLoader = new \Doctrine\Common\ClassLoader(
'Doctrine',
APPLICATION_PATH . '/../library/'
);
$classLoader->register();
$classLoader = new \Doctrine\Common\ClassLoader(
'Repositories',
APPLICATION_PATH . '/../library/Model'
);
$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\ApcCache;
$config->setMetadataCacheImpl($cache);
$config->setQueryCacheImpl($cache);
// choosing the driver for our database schema
// we'll use annotations
$driver = $config->newDefaultAnnotationDriver(
APPLICATION_PATH . '/../library/Model'
);
$config->setMetadataDriverImpl($driver);
// set the proxy dir and set some options
$config->setProxyDir(APPLICATION_PATH . '/../library/Model/Proxies');
$config->setAutoGenerateProxyClasses(true);
$config->setProxyNamespace('Model\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['conn']['driv'],
'user' => $connectionSettings['conn']['user'],
'password' => $connectionSettings['conn']['pass'],
'dbname' => $connectionSettings['conn']['dbname'],
'host' => $connectionSettings['conn']['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;
}
我怎么能解决这个问题?
答案 0 :(得分:1)
您的_initAutoload完全没必要。 只需添加
autoloadernamespaces[] = Default
autoloadernamespaces[] = Doctrine
到你的application.ini
答案 1 :(得分:1)
我同意_initAutoload()不是必需的,但我怀疑你在application.ini中需要这个:
autoloaderNamespaces[] = "Doctrine"
autoloaderNamespaces[] = "Model"
答案 2 :(得分:0)
如果你刚刚开始你的项目,我会建议使用zf2(beta5最后的测试版:http://framework.zend.com/zf2/blog/entry/Zend-Framework-2-0-0beta5-Released)
这是我用于我的项目zf2 + doctrine 2
http://www.jasongrimes.org/2012/01/using-doctrine-2-in-zend-framework-2/