2012-06-02 1 views
3

내 클래스에 명시 적으로 네임 스페이스를 지정하지 않고도 내 프로젝트에서 Doctrine을 사용하고 있습니다. 이로 인해 내 코드를 별도의 하위 디렉토리로 구성하는 데 문제가 발생했습니다 (또는 적어도 그렇게 보였습니다). 이와 같이 나는 코드에서 네임 스페이스를 구현하려고 시도했지만 어려움을 겪고 있으며 여기에 수많은 솔루션을 시도해 보았습니다. 물어볼 필요가 있습니다.Doctrine 2와 namespace가있는 젠드 프레임 워크 1.11

내가 표준 프로젝트 구조있어

: 나는 (잘 작동 내 코드에서 네임 스페이스없이) 다음있어 내 부트 스트랩에서

application/ 
--models/ 
--services/ 
--controllers/ 
..etc 

을 : 내가 추가

/** 
* Initialize Doctrine 
* @return Doctrine_Manager 
*/ 
public function _initDoctrine() { 
    // include and register Doctrine's class loader 
    require_once('doctrine/Doctrine/Common/ClassLoader.php'); 

    $autoloader = \Zend_Loader_Autoloader::getInstance(); 

    require_once('doctrine/Doctrine/Common/ClassLoader.php'); 
    $commonLoader = new \Doctrine\Common\ClassLoader('Doctrine\Common', 'doctrine'); 
    $autoloader->pushAutoloader(array($commonLoader, 'loadClass'), 'Doctrine\Common'); 

    $dbalLoader = new \Doctrine\Common\ClassLoader('Doctrine\DBAL', 'doctrine'); 
    $autoloader->pushAutoloader(array($dbalLoader, 'loadClass'), 'Doctrine\DBAL'); 

    $ormLoader = new \Doctrine\Common\ClassLoader('Doctrine\ORM', 'doctrine'); 
    $autoloader->pushAutoloader(array($ormLoader, 'loadClass'), 'Doctrine\ORM'); 

    $modelLoader = new \Doctrine\Common\ClassLoader(NULL, APPLICATION_PATH . "/models"); 
    $autoloader->pushAutoloader(array($modelLoader, 'loadClass'), ''); 

    // 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\ArrayCache; 
    $config->setMetadataCacheImpl($cache); 
    $config->setQueryCacheImpl($cache); 

    // choosing the driver for our database schema 
    // we'll use annotations 
    $driver = $config->newDefaultAnnotationDriver(
     APPLICATION_PATH . '/models' 
     ); 
    $config->setMetadataDriverImpl($driver); 

    // set the proxy dir and set some options 
    $config->setProxyDir(APPLICATION_PATH . '/models/Proxies'); 
    $config->setAutoGenerateProxyClasses(true); 
    //$config->setAutoGenerateProxyClasses(false); 
    $config->setProxyNamespace('App\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; 
} 

namespace models; 

내 모델 클래스 각각에 대해 다음과 같이 부트 스트랩을 업데이트하십시오. Ex 나는 무엇을 놓치고

public function indexAction() 
{ 
    $this->_helper->layout()->title = "Your applications"; 
    $this->_helper->layout()->description = "Create, edit and view all applications you have registered with us."; 
    $this->view->applicationList = $this->entityManager->getRepository("Application")->findAll(); 
} 

다음과 같이

$modelLoader = new \Doctrine\Common\ClassLoader('models', APPLICATION_PATH . "/models"); 
$autoloader->pushAutoloader(array($modelLoader, 'loadClass'), 'models'); 

그냥 완성도, 내가 내 컨트롤러에서 해당 모델을 참조 : ception (응용 프로그램 내 모델 중 하나입니다) "클래스 응용 프로그램은 존재하지 않는다"? 나는 그것이 분명하지만 정말로 지금 내 머리카락을 꺼내고 있다고 확신한다.

답변

1

훨씬 더 많이 검색 한 후 this video (로그인 필요)을 우연히 발견했습니다.

기본적으로 웹 세미나에 따라 해결 된 방식은 내 항목의 네임 스페이스를 지정하고/라이브러리 디렉토리 아래에 저장하는 것이 었습니다. 그런 다음 실제 앱에서 사용할 때마다 네임 스페이스를 통해 액세스합니다.