2011-12-07 24 views
1

試圖導入(返回的Yii配置之前),而在config/main.php一類:Yii框架:導入類而在config/main.php文件

//class LanguageSettings is placed directly in protected/components/LanguageSettings.php 
Yii::import('application.components.*'); 
LanguageSettings::currentLanguage(); 

導致該致命錯誤:

Fatal error: Uncaught exception 'CException' with message 
'Alias "application.components.*" is invalid. Make sure it points to an existing 
directory or file.' in C:\xampp\htdocs\yii\framework\YiiBase.php: 

爲什麼?在導入配置數組之前,Yi Yii能否正確解析別名?

回答

1

對不起,我不認爲它會工作,因爲basePath尚未設置,因此Yii無法計算application.components。*所指的位置。

+0

謝謝你的回答。有沒有其他路徑可以導入(手動)? – Sebastian

+0

好吧,因爲通常basePath(在config/main.php中)定義爲dirname(__ FILE __)。DIRECTORY_SEPARATOR。'..'你可以在main.php頂部的變量($ myBasePath)中定義它,然後手動執行import_once($ myBasePath。'/components/myComponent.php')繞過Yii的自動導入功能。有點哈克,雖然... – stratosgear

+0

哈克,但有幫助。謝謝 ! ps。 import_once = include/require_once。 – Sebastian