Kirk
Kirk

Reputation: 1845

Yii 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 this class , but I can namespace the sub directory classes.

Let me know if I've left out some vital information. Just in case, here is the init file I'm running:

// 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();

All files follow the naming convention of being identical to the class.

I've been through this as well as some other SO questions and Yii files: Yii Framework Namespace Docs

Thanks.

Upvotes: 2

Views: 4064

Answers (1)

Kirk
Kirk

Reputation: 1845

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

Upvotes: 1

Related Questions