2013-12-09 89 views
2

全部,Yii自動加載名稱空間

類似的問題已被提出,但我似乎無法弄清楚。我有一個ConsoleCommand運行,我想命名空間的文件。結構如下:

/protected/commands/Ingestion/(根,包含IngestionCommand.php)。 /protected/commands/Ingestion/ingestionServices/(包含此命令依賴的服務)。

奇怪的部分是,當我沒有將「命名空間攝取」放在我的IngestionCommand的頂部,而是將所有其他命名空間的東西放在一邊時,一切運行良好。我只想把這個類轉換的命名空間攝入,但是PHP引發此錯誤:

PHP Fatal error: Cannot redeclare class Ingestion\IngestionCommand in /mnt/hgfs/linkFolder/devro/CFXJobTrack/monoMassPrintTemplate/protected/commands/Ingestion/IngestionCommand.php on line 166 
PHP Error[2]: include(/mnt/hgfs/linkFolder/devro/CFXJobTrack/monoMassPrintTemplate/protected/config/../commands/Ingestion/Iterator.php): failed to open stream: No such file or directory... 

我也不知道是什麼文件的Iterator.php故障是所有關於要麼... 我用NetBeans和Finder(在Mac上)搜索此類的其他實例,但沒有任何實例。這裏是我的.conf的一部分:

'basePath'=>dirname(__FILE__).DIRECTORY_SEPARATOR . '..', 
    'name'=>'Cron', 
    'preload'=>array('log'), 
    'aliases'=> array(
     'Ingestion' => dirname(__FILE__) . '/../commands/Ingestion/', 
    ), 
//autoload class for use in yii. 
    'import'=>array(
      'application.components.*', 
      'application.models.*', 
      'application.extensions.sftp.*', 
      'application.components.container.*', 
      'application.commands.*', 
      'Ingestion.*', 
      'Ingestion.ingestionServices.*', 

    ), 
    'commandMap'=> array( 
     'ingestion' =>array(
      'class' =>'Ingestion.IngestionCommand', 
     ), 

當我註釋掉行:

'Ingestion' => dirname(__FILE__) . '/../commands/Ingestion/',

PHP的抱怨是這樣的:

PHP Error[2]: include(IngestionCommand.php): failed to open stream: No such file or directory 
    in file /mnt/hgfs/linkFolder/devro/CFXJobTrack/yii/framework/YiiBase.php at line 421... 

這告訴我只有點我m試圖加載這個類就在那裏,但我可能是錯的。任何人都知道我錯過了什麼/做錯了什麼?

我不明白爲什麼我不能命名空間這個類,但我可以命名空間的子目錄類。

讓我知道我是否遺漏了一些重要信息。以防萬一,這裏是我正在運行的init文件:

// change the following paths if necessary 
$yii=dirname(__FILE__).'/../../../yii/framework/yii.php'; 
$config=dirname(__FILE__).'/../config/cron.php'; 


// remove the following lines when in production mode 
defined('YII_DEBUG') or define('YII_DEBUG',true); 
// specify how many levels of call stack should be shown in each log message 
defined('YII_TRACE_LEVEL') or define('YII_TRACE_LEVEL',3); 

require_once($yii); 
require_once(dirname(__FILE__).'/../components/ConsoleApplication.php'); 
Yii::createApplication('ConsoleApplication',$config)->run(); 

所有文件都遵循命名約定與該類相同。

我經歷過這個問題,以及其他一些做題和Yii的文件: Yii Framework Namespace Docs

感謝。

回答

1

通過將攝取'class'參數更改爲'\ Ingestion \ IngestionCommand'來解決。 (在commandMap下)。

相關問題