2010-09-06 51 views
1

我有一個Classloader添加到Doctrine 2項目的問題。 我有這樣簡單的目錄結構:Doctrine 2 Classloader奇怪的行爲 - 類錯誤的路徑

  • 配置(引導文件)
  • HTML(文檔根目錄與模板/圖像/ JS等)
  • PHP
  • 實體(教條2個實體)
  • 響應(一些傳輸對象)
  • 服務(處理api和業務邏輯 - 像java中的會話bean)

每個php子目錄都屬於它自己的名稱空間(與目錄名稱相同)。
我想使用上述類加載器加載這三種不同的套餐,所以我的自舉看起來是這樣的:

$classLoader = new \Doctrine\Common\ClassLoader('Doctrine', $lib); 
$classLoader->register(); 

$responsesCL = new \Doctrine\Common\ClassLoader('Responses', __DIR__.'/../php'); 
$responsesCL->register(); 

$entitiesCL = new \Doctrine\Common\ClassLoader('Entities', __DIR__.'/../php'); 
$entitiesCL->register(); 

$servicesCL = new \Doctrine\Common\ClassLoader('Services', __DIR__.'/../php'); 
$servicesCL->register(); 

大膽DIR實際上是__ DIR __ PHP不變。現在

,我在我的服務包指的是實體的,這纔是問題的開始,由於某種原因,我得到由於未找到文件問題的錯誤,例如:

無法打開需要 「 /var/www/projects/PlatformManagement/config/../php/Services/Entities/User.php' (include_path ='。:/ usr/share/pear:/ usr/share/php') in /usr/share/pear/Doctrine/Common/ClassLoader.php on line

不知何故,路徑中還有額外的'服務',顯然它不是有效的路徑。我有點困惑爲什麼那個額外的目錄呢?我tripple檢查所有名稱空間,電話,他們都沒問題。

我需要另一雙眼睛看,我假設我在這裏失去了一些明顯的東西,但無法發現它:

哦,這是最新的Doctrine 2 Beta(4)和php 5.3.3上的Fedora,如果這是任何幫助。

感謝, 格雷格

+0

當我試圖使用類從包的問題了。我使用Entities \ ClassName.class而不是\ Entities \ ClassName.class – Greg 2010-09-07 17:30:34

回答

0

是否有任何類似學說\ ORM \工具\ SETUP :: registerAutoloadPEAR()?

Doctrine的Autoloader可能會產生意外的行爲,因爲它會根據PHP包含路徑加載類。

this

在你的情況下,實體應該有

namespace Entities; 

聲明,而不是別的。

和使用單位像下面,

use Entities\User; 
new User;