2010-07-30 2 views
3

난 내가 제대로하고있는 중이 야 확실하지 않다 그래도 ...젠드 프레임 워크를 Doctrine 2와 통합하는 올바른 방법인가요?

디렉토리 구조

/application 
    /models 
     /User.php // following classes are doctrine models 
     /Post.php 
     /Tag.php 
    /proxies 
     /...  // proxy classes generated by doctrine 
    /...   // other zend classes 

bootstrap.php>_initDoctrine(), 젠드의에 교리 2의 자동 로더를 통합 관리하는 것 내가이

// setup Zend & Doctrine Autoloaders 
require_once "Doctrine/Common/ClassLoader.php"; 

$zendAutoloader = Zend_Loader_Autoloader::getInstance(); 

// $autoloader = array(new \Doctrine\Common\ClassLoader(), 'loadClass'); 

$autoloader = array(new \Doctrine\Common\ClassLoader('Symfony'), 'loadClass'); 
$zendAutoloader->pushAutoloader($autoloader, 'Symfony\\'); 
$autoloader = array(new \Doctrine\Common\ClassLoader('Doctrine'), 'loadClass'); 
$zendAutoloader->pushAutoloader($autoloader, 'Doctrine\\'); 
$autoloader = array(new \Doctrine\Common\ClassLoader('DoctrineExtensions'), 'loadClass'); 
$zendAutoloader->pushAutoloader($autoloader, 'DoctrineExtensions\\'); 
$autoloader = array(new \Doctrine\Common\ClassLoader('Application\\Models', realpath(__DIR__ . '/..')), 'loadClass'); 
$zendAutoloader->pushAutoloader($autoloader, 'Application\\Models\\'); 
$autoloader = array(new \Doctrine\Common\ClassLoader('Application\\Proxies', realpath(__DIR__ . '/..')), 'loadClass'); 
$zendAutoloader->pushAutoloader($autoloader, 'Application\\Proxies'); 
$autoloader = array(new \Doctrine\Common\ClassLoader('DoctrineExtensions'), 'loadClass'); 
$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); 
$driverImpl = $config->newDefaultAnnotationDriver(realpath(__DIR__ . '/models')); 
$config->setMetadataDriverImpl($driverImpl); 
$config->setQueryCacheImpl($cache); 
$config->setProxyDir(realpath(__DIR__ . '/proxies')); 
$config->setProxyNamespace('Application\\Proxies'); 
$config->setAutoGenerateProxyClasses(true); 

$connectionOptions = array(
    '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; 

한 질문은 내가 newDefaultAnnotationDriver() 및에 상대 경로를 사용할 수있다내가 안전하다고 말하는 것이 더 안전 할 것입니다. realpath()__DIR__을 사용하여 전체 경로를 만드는 것이 가장 안전할까요?

또한 doctrine이 각 네임 스페이스에 대해 자동 로딩 1을 설정해야하는지 궁금한가요? 그 오토로더를 밀었습니까?

예를 들어 here이 실행 가능한지 궁금합니다. 기본적으로 그는

protected function _initDoctrine() 
{ 
    // Create the doctrine autoloader and remove it from the spl autoload stack (it adds itself) 
    require_once 'Doctrine/Common/ClassLoader.php'; 
    $doctrineAutoloader = array(new \Doctrine\Common\ClassLoader(), 'loadClass'); 
    spl_autoload_unregister($doctrineAutoloader); 

    // Fetch the global Zend Autoloader 
    $autoloader = Zend_Loader_Autoloader::getInstance(); 

    // Push the doctrine autoloader to load for the Doctrine\ namespace 
    $autoloader->pushAutoloader($doctrineAutoloader, 'Doctrine\\'); 
} 

내가 그 교리 2 샌드 박스에서 ClassLoader에 매개 변수를 전달할 필요가없는 이유, 네임 스페이스가 1 1, 자동 로더에 전달하고, 오토로더가 등록 궁금해 ... 같은 뭔가를 사용했다. spl_autoload_unregister($doctrineAutoloader)이 필요한 이유는 무엇입니까?

답변

3

좋아요. 예라고 말하면 닫고

관련 문제