Autoloading Namespaces

All,

Similar questions have been posed, but I can’t seem to figure this out. I have a ConsoleCommand that runs and I was wanting to namespace the files. The structure is as follows:

/protected/commands/Ingestion/ (root, contains the IngestionCommand.php ).

/protected/commands/Ingestion/ingestionServices/ (contains services this command depends on).

The strange part is, when I don’t put ‘namespace Ingestion’ at the top of my IngestionCommand but leave all my other namespace stuff alone, everything runs fine. I just want to put this class into the namespace Ingestion, but php throws this error:




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...



I also don’t know what file the Iterator.php failure is all about either…

I’ve used NetBeans and Finder (on a mac) to search for other instances of this class and I don’t have any. Here’s part of my .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',

	    ),

When I comment out the line


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

php complains like this:




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...



That tells me the only spot I’m attempting to load this class is right there, but I’m probably wrong. Anyone know what I’m missing/ doing wrong? I’m failing to understand why I can’t namespace a class in the root directory of the namespace, but the sub directories are fine. Thanks.

Solved by changing the ingestion ‘class’ parameter to ‘\Ingestion\IngestionCommand’. (under commandMap).