我正在使用Zend Framework来创建Web应用程序。基于几个建议,我选择了Doctrine作为我的RDBM系统。
;---------------------------------------------------
; DOCTRINE CONFIGURATION
;---------------------------------------------------
resources.entityManager.connection.driver = "pdo_mysql"
resources.entityManager.connection.host = "localhost"
resources.entityManager.connection.dbname = "private"
resources.entityManager.connection.user = "private"
resources.entityManager.connection.password = "private"
resources.entityManager.connection.entities = APPLICATION_PATH "/models"
resources.entityManager.connection.proxies.location = APPLICATION_PATH "/models/Proxies"
resources.entityManager.connection.proxies.ns = "Proxies"
; According to Doctrine manual, this should be true for
; development, and false for production
resources.entityManager.connection.proxies.generate = true
以上是我在Zend application.ini中的Doctrine配置。一切都运行正常,但我想事先知道如何在不使用CLI的情况下手动生成代理,原因有几个。首先,Doctrine 2.0文档提到自动生成代理会导致性能问题。其次,我还没有弄清楚如何使用Doctrine CLI,特别是我已经将项目开发移动到共享服务器盒而没有命令提示符访问。
我一直在通过创建类手动生成Doctrine实体。如何手动生成Doctrine代理?
答案 0 :(得分:4)
我找到了生成代理的简便方法:
$proxyDir = null; //to genearate to default proxy dir
$proxyFactory = $em->getProxyFactory();
$metadatas = $em->getMetadataFactory()->getAllMetadata();
$proxyFactory->generateProxyClasses($metadatas, $proxyDir);
生成实体使用:
$classes = $em->getClassMetadataFactory()->getAllMetadata();
$generator = new \Doctrine\ORM\Tools\EntityGenerator();
$generator->setGenerateAnnotations(true);
$generator->setGenerateStubMethods(true);
$generator->setRegenerateEntityIfExists(false);
$generator->setUpdateEntityIfExists(true);
$generator->generate($classes, '/path/to/generate/entities');