全部,
也有人提出过类似的问题,但我似乎想不通。我有一个正在运行的ConsoleCommand,我想为这些文件命名名称空间。结构如下:
/protected/commands/Ingestion/
(root,包含IngestionCommand.php)。/protected/commands/Ingestion/ingestionServices/
(包含此命令所依赖的服务)。
奇怪的是,当我不把"namespace Ingestion"放在IngestionCommand的顶部,而是把所有其他命名空间的东西都放在一边时,一切都很好。我只想把这个类放进名称空间Ingestion,但是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...
这告诉我试图加载这个类的唯一地方就在那里,但我可能错了。有人知道我遗漏了什么/做错了什么吗?
我不明白为什么我不能为这个类命名,但我可以为子目录类命名。
如果我遗漏了一些重要信息,请告诉我。以防万一,下面是我正在运行的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();
所有文件都遵循与类相同的命名约定。
我已经经历了这个以及其他一些SO问题和Yii文件:Yii框架命名空间文档
谢谢。
通过将摄入"class"参数更改为"''ingestion''IngestionCommand"来解决。(在commandMap下)。