Can't load my models in console application

(Solved now, look below)

Look, I am having this console.php configuration file, the db connection works (I have tried the createCommand - it works), but I can’t load my models to use AR, which is pretty annoying.




 1 <?php

  2

  3 // This is the configuration for yiic console application.

  4 // Any writable CConsoleApplication properties can be configured here.

  5 return array(

  6         'basePath'=>dirname(__FILE__).DIRECTORY_SEPARATOR.'..',

  7         'name'=>'My Console Application',

  8         'components'=>array(

  9

 10                 'db'=>array(

 11                         'connectionString' => 'mysql:host=127.0.0.1;dbname=xxx',

 12                         'emulatePrepare' => true,

 13                         'username' => 'root',

 14                         'password' => 'yyy',

 15                         'charset' => 'utf8',

 16                         'schemaCachingDuration' => '3600',

 17                         'enableProfiling'=> 'true',

 18                         'enableParamLogging' => 'true',

 19                 ),

 20

 21                 'import'=>array(

 22                 'application.models.*',

 23

 24                 ),

 25         ),

 26 );




Then I’m trying to do this from my console application:

$hs=new Historyset;

And then it is all over. Yii says:

PHP Error[2]: YiiBase::include(Historyset.php): failed to open stream: No such file or directory

And gives this stack trace (pretty long):


#0  CConsoleApplication->displayError(2, YiiBase::include(Historyset.php): failed to open stream: No such file or directory, /var/www/framework/YiiBase.php, 341) called at [/var/www/framework/base/CErrorHandler.php:207]

#1  CErrorHandler->handleError(CErrorEvent Object ([code] => 2,[message] => YiiBase::include(Historyset.php): failed to open stream: No such file or directory,[file] => /var/www/framework/YiiBase.php,[line] => 341,[sender] => CConsoleApplication Object ([commandMap] => Array (),[] => /var/www/metko/adm_new/protected/commands,[] => CConsoleCommandRunner Object ([commands] => Array ([countratio] => /var/www/metko/adm_new/protected/commands/CountRatioCommand.php),[] => index_console.php,[] => ,[] => ),[name] => My Console Application,[charset] => UTF-8,[sourceLanguage] => en_us,[] => ,[] => /var/www/metko/adm_new/protected,[] => ,[] => ,[] => ,[] => ,[] => ,[] => ,[preload] => Array (),[behaviors] => Array (),[] => ,[] => ,[] => ,[] => ,[] => ,[] => Array (),[] => Array (),[] => Array ([db] => CDbConnection Object ([connectionString] => mysql:host=127.0.0.1;dbname=metko_new,[username] => root,[password] => test,[schemaCachingDuration] => 3600,[schemaCachingExclude] => Array (),[schemaCacheID] => cache,[autoConnect] => 1,[charset] => utf8,[emulatePrepare] => 1,[enableParamLogging] => true,[enableProfiling] => true,[tablePrefix] => ,[initSQLs] => ,[] => Array (),[] => 1,[] => PDO Object (),[] => ,[] => ,[behaviors] => Array (),[] => 1,[] => ,[] => ),[errorHandler] => CErrorHandler Object ([maxSourceLines] => 25,[adminInfo] => the webmaster,[discardOutput] => 1,[errorAction] => ,[] => ,[behaviors] => Array (),[] => 1,[] => ,[] => )),[] => Array ([coreMessages] => Array ([class] => CPhpMessageSource,[language] => en_us,[basePath] => /var/www/framework/messages),[messages] => Array ([class] => CPhpMessageSource),[securityManager] => Array ([class] => CSecurityManager),[statePersister] => Array ([class] => CStatePersister),[urlManager] => Array ([class] => CUrlManager),[request] => Array ([class] => CHttpRequest),[format] => Array ([class] => CFormatter),[import] => Array ([0] => application.models.*)),[] => ,[] => ),[handled] => 1,[] => ,[] => )) called at [/var/www/framework/base/CErrorHandler.php:98]

#2  CErrorHandler->handle(CErrorEvent Object ([code] => 2,[message] => YiiBase::include(Historyset.php): failed to open stream: No such file or directory,[file] => /var/www/framework/YiiBase.php,[line] => 341,[sender] => CConsoleApplication Object ([commandMap] => Array (),[] => /var/www/metko/adm_new/protected/commands,[] => CConsoleCommandRunner Object ([commands] => Array ([countratio] => /var/www/metko/adm_new/protected/commands/CountRatioCommand.php),[] => index_console.php,[] => ,[] => ),[name] => My Console Application,[charset] => UTF-8,[sourceLanguage] => en_us,[] => ,[] => /var/www/metko/adm_new/protected,[] => ,[] => ,[] => ,[] => ,[] => ,[] => ,[preload] => Array (),[behaviors] => Array (),[] => ,[] => ,[] => ,[] => ,[] => ,[] => Array (),[] => Array (),[] => Array ([db] => CDbConnection Object ([connectionString] => mysql:host=127.0.0.1;dbname=metko_new,[username] => root,[password] => test,[schemaCachingDuration] => 3600,[schemaCachingExclude] => Array (),[schemaCacheID] => cache,[autoConnect] => 1,[charset] => utf8,[emulatePrepare] => 1,[enableParamLogging] => true,[enableProfiling] => true,[tablePrefix] => ,[initSQLs] => ,[] => Array (),[] => 1,[] => PDO Object (),[] => ,[] => ,[behaviors] => Array (),[] => 1,[] => ,[] => ),[errorHandler] => CErrorHandler Object ([maxSourceLines] => 25,[adminInfo] => the webmaster,[discardOutput] => 1,[errorAction] => ,[] => ,[behaviors] => Array (),[] => 1,[] => ,[] => )),[] => Array ([coreMessages] => Array ([class] => CPhpMessageSource,[language] => en_us,[basePath] => /var/www/framework/messages),[messages] => Array ([class] => CPhpMessageSource),[securityManager] => Array ([class] => CSecurityManager),[statePersister] => Array ([class] => CStatePersister),[urlManager] => Array ([class] => CUrlManager),[request] => Array ([class] => CHttpRequest),[format] => Array ([class] => CFormatter),[import] => Array ([0] => application.models.*)),[] => ,[] => ),[handled] => 1,[] => ,[] => )) called at [/var/www/framework/base/CApplication.php:649]

#3  CApplication->handleError(2, YiiBase::include(Historyset.php): failed to open stream: No such file or directory, /var/www/framework/YiiBase.php, 341, Array ([className] => Historyset)) called at [/var/www/framework/YiiBase.php:341]

#4  YiiBase::autoload() called at [/var/www/framework/YiiBase.php:341]

#5  YiiBase::autoload(Historyset)

#6  spl_autoload_call(Historyset) called at [/var/www/metko/adm_new/protected/commands/CountRatioCommand.php:12]

#7  CountRatioCommand->run(Array ()) called at [/var/www/framework/console/CConsoleCommandRunner.php:62]

#8  CConsoleCommandRunner->run(Array ([0] => index_console.php,[1] => CountRatio)) called at [/var/www/framework/console/CConsoleApplication.php:88]

#9  CConsoleApplication->processRequest() called at [/var/www/framework/base/CApplication.php:135]

#10 CApplication->run() called at [/var/www/metko/adm_new/index_console.php:13]



What should I do? I am terribly confused!

Thanks in advance.

SOLVED!

There was error in the configuration file, the ‘import’ array should have been 1 level higher. The correct one is like:


return array(

        'basePath'=>dirname(__FILE__).DIRECTORY_SEPARATOR.'..',

        'name'=>'My Console Application',

        'components'=>array(


                'db'=>array(

                        'connectionString' => 'mysql:host=127.0.0.1;dbname=metko_new',

                        'emulatePrepare' => true,

                        'username' => 'root',

                        'password' => 'test',

                        'charset' => 'utf8',

                        'schemaCachingDuration' => '3600',

                        'enableProfiling'=> 'true',

                        'enableParamLogging' => 'true',

                ),


                ),

                'import'=>array(

                'application.models.*',


        ),

);



Thanks everybody who tried to think about it :)