我想在我的ZendFramework(v1.11)应用程序中使用Doctrine(v2.4),这是我从头开始的。有一些文章描述了这种集成,但它们看起来相当复杂,有点过时了。有没有相当简单的方法来连接ZF1和Doctrine2?
我已经将其实现为应用程序资源(扩展'Zend_Application_Resource_ResourceAbstract
)
代码很长,所以下面是要求的顶级检查列表。
-
创建原则实体管理器配置实例 (
Doctrine'ORM'Configuration
)。$config = new Doctrine'ORM'Configuration();
-
使用所需的数据(元数据驱动程序、缓存配置等)填充配置。教义的文档在这里是一个很好的参考,需要什么(http://docs.doctrine-project.org/en/latest/reference/configuration.html)
此处的示例使用注释驱动程序:
$driver = new Driver'AnnotationDriver(
new Annotations'CachedReader(new Annotations'AnnotationReader(), new Cache'ArrayCache()),
$entityDirs
);
$config->setMetadataDriverImpl($driver);
- 最后,将此新配置实例传递给静态实体管理器
EntityManager::create
例如($options
这里是数据库连接信息,如上面的链接所示)
$entityManager = EntityManager::create($options['database'], $config);
看看我的完整来源,至少它会给你一个良好的开端:
https://github.com/alex-patterson-webdev/Multiverse/blob/master/lib/Multiverse/Application/Resource/Entitymanager.php