2011-02-26 68 views
1

我對ORM和Doctrine非常陌生,所以請耐心等待。學說:創建模式(Unknown Entity namespace alias'C')。

我現在或多或少地遵循入門教程(只是用不同的表格來使它更有趣)。我已經創建了兩個YAML文件定義我的模式,這是非常簡單的:

用戶:

User: 
    type: entity 
    table: users 
    id: 
    id: 
     type: integer 
     generator: AUTO 
    fields: 
    firstName: 
     type: string 
    lastName: 
     type: string 
    birthdate: 
     type: datetime 
    email: 
     type: string 
    username: 
     type: string 
    password: 
     type: string 
    oneToMany: 
    pages: 
     targetEntity: Page 
     mappedBy: user 

頁:

Page: 
    type: entity 
    table: pages 
    id: 
    id: 
     type: integer 
     generator: 
     strategy: AUTO 
    fields: 
    name: 
     type: string 
    content: 
     type: text 
    manyToOne: 
    user: 
     targetEntity: User 
     inversedBy: pages 

現在我試圖用SchemaTool創建數據庫架構。當我運行這段代碼:

$em = Zend_Registry::get('entityManager'); 
$tool = new \Doctrine\ORM\Tools\SchemaTool($em); 
$classes = array(
    $em->getClassMetadata('Entities\User'), 
    $em->getClassMetadata('Entities\Page') 
); 

我得到這個錯誤:

#0 C:\inetpub\wwwroot\zend\library\Doctrine\ORM\Configuration.php(150): 
Doctrine\ORM\ORMException::unknownEntityNamespace('C') 
#1 
C:\inetpub\wwwroot\zend\library\Doctrine\ORM\Mapping\ClassMetadataFactory.php(155): 
Doctrine\ORM\Configuration->getEntityNamespace('C') 
#2 C:\inetpub\wwwroot\zend\library\Doctrine\ORM\EntityManager.php(247): 
Doctrine\ORM\Mapping\ClassMetadataFactory->getMetadataFor('C:\inetpub\wwwr...') 
#3 
C:\inetpub\wwwroot\zend\application\modules\default\controllers\DoctrineUtilController.php(16): 
Doctrine\ORM\EntityManager->getClassMetadata('C:\inetpub\wwwr...') 
#4 C:\inetpub\wwwroot\zend\library\Zend\Controller\Action.php(513): 
DoctrineUtilController->generateModelsAction() 
#5 C:\inetpub\wwwroot\zend\library\Zend\Controller\Dispatcher\Standard.php(295): 
Zend_Controller_Action->dispatch('generateModelsA...') 
#6 C:\inetpub\wwwroot\zend\library\Zend\Controller\Front.php(954): 
Zend_Controller_Dispatcher_Standard->dispatch(Object(Zend_Controller_Request_Http), 
Object(Zend_Controller_Response_Http)) 
#7 C:\inetpub\wwwroot\zend\application\Bootstrap.php(177): 
Zend_Controller_Front->dispatch() 
#8 C:\inetpub\wwwroot\zend\library\Zend\Application.php(366): 
Bootstrap->run() 
#9 C:\inetpub\wwwroot\zend\public\index.php(54): Zend_Application->run() 
#10 {main}  
    $tool->createSchema($classes); 

任何想法在那裏可能是一個問題嗎?


附加信息以防萬一。這就是我如何在Bootstrap.php文件中創建實體管理器:

protected function _initDoctrine() { 
    // (1) 
    $config = new \Doctrine\ORM\Configuration(); 

    // Proxy Configuration (2) 
    $config->setProxyDir(APPLICATION_PATH.'/proxies'); 
    $config->setProxyNamespace('Application\Proxies'); 
    $config->setAutoGenerateProxyClasses(('development' === APPLICATION_ENVIRONMENT)); 

    // Mapping Configuration (3) 
    $driverImpl = new Doctrine\ORM\Mapping\Driver\XmlDriver(APPLICATION_PATH.'/configs/mappings/yml'); 
    $config->setMetadataDriverImpl($driverImpl); 

    // Caching Configuration (4) 
    if ('development' === APPLICATION_ENVIRONMENT) { 
     $cache = new \Doctrine\Common\Cache\ArrayCache(); 
    } else { 
     $cache = new \Doctrine\Common\Cache\ApcCache(); 
    } 
    $config->setMetadataCacheImpl($cache); 
    $config->setQueryCacheImpl($cache); 

    // database configuration parameters (5) 
    $conn = array(
     'driver' => $this->configuration->database->adapter, 
     'user' => $this->configuration->database->username, 
     'password' => $this->configuration->database->password, 
     'dbname' => $this->configuration->database->dbname 
    ); 

    // obtaining the entity manager (6) 
    $evm = new Doctrine\Common\EventManager(); 
    $this->entityManager = \Doctrine\ORM\EntityManager::create($conn, $config, $evm); 
    Zend_Registry::set('entityManager', $this->entityManager); 
} 

回答

1

似乎路徑定義存在問題。

Doctrine\ORM\Mapping\ClassMetadataFactory->getMetadataFor('C:\inetpub\wwwr...') 

這不應該是絕對路徑,如學說假設是類的名字命名空間,所以它需要的是「C:\」的命名空間。

所以這是配置或自動加載器的問題。

在Doctrine中有一個包含基本工作配置的沙箱,您可以將其作爲起點。

+0

@Hakan Deryal Doctrine 2還沒有沙箱,只有版本1.2,所以我不能這樣做。我根據本教程設置了自動加載器和配置:http://snipplr.com/view/38628/integrating-zend-framework-110-with-doctrine-2-using-doctrines-autoloader/ – 2011-02-27 12:36:08

+0

我不知道關於框架的任何事情,所以不能對指南進行評論。但錯誤表明我提到的問題。 Doctrine2有一個沙箱。在git repo中,在tools目錄下。 – 2011-02-27 13:38:10

+0

那麼,我在Doctrine網站上找不到沙盒的任何鏈接。 – 2011-02-27 14:56:59