2012-02-19 9 views
6

젠드 프레임 워크를 사용하여 웹 응용 프로그램을 만듭니다. 몇 가지 권장 사항에 따라, 나는 RDBM 시스템으로 Doctrine을 선택했다.Doctrine에서 CLI없이 수동으로 프록시를 생성하는 방법은 무엇입니까?

;--------------------------------------------------- 
; 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 프록시를 수동으로 어떻게 수동으로 생성합니까?

$proxyDir = null; //to genearate to default proxy dir 
    $proxyFactory = $em->getProxyFactory(); 
    $metadatas = $em->getMetadataFactory()->getAllMetadata(); 
    $proxyFactory->generateProxyClasses($metadatas, $proxyDir); 

엔티티를 사용 생성 :

답변

4

나는 프록시를 생성하는 쉬운 방법을 발견했습니다

우리는 엔티티, 코드합니다 ($ metadatas 라인)의 그러나 세 번째 줄이
$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'); 
+0

우리에게 오류가 발생했습니다 : 'Doctrine \ ORM \ Mapping \ MappingException'메시지와 함께 잡히지 않는 예외 '파일 매핑 드라이버에 올바른 디렉토리 경로가 있어야하지만 주어진 경로가 올바르지 않은 것 같습니다!' C : \ Zend \ Apache2 \ htdocs \ Webate \ library \ Doctrine \ ORM \ Mapping \ MappingException.php : 193 – Furyvore

+0

EntityManager에서 프록시 경로를 설정해야합니다. 이전 프로젝트의 코드입니다 :'$ config = new \ Doctrine \ ORM \ Configuration; \t \t $ config-> setMetadataCacheImpl (self :: getCache()); \t \t $ config-> setMetadataDriverImpl (새 \ qweb \ driver \ DoctrineYml (QWEB_MODULE)); \t \t $ config-> setEntityNamespaces (array ('base')); \t \t $ config-> setProxyDir (DOCTRINE_PROXIES); \t \t $ config-> setProxyNamespace ('proxy'); \t \t $ 연결 = \ Doctrine \ DBManager \ DriverManager :: getConnection (self :: loadYml (QWEB_CONFIG.DIRECTORY_SEPARATOR.'databases.yml '))); \t \t $ em = \ Doctrine \ ORM \ EntityManager :: create ($ connection, $ config);' –