corvus
(Yiiframework)
March 8, 2011, 5:20pm
1
hi!
i have a problem when i want to use my exisiting models from /protected/models with yiic.
i have created /protected/commands/StatisticCommand.php with this content:
class StatisticCommand extends CConsoleCommand
{
public function run($args)
{
echo "run";
$model_statistic = StatisticOnline::model()->findAll();
var_dump($model_statistic);
}
public function actionDay() {
echo "day";
}
}
in the console i am in the protected folder.
when i try to run statistic (./yiic statistic) i get an include error.
PHP Error[2]: include(StatisticOnline.php): failed to open stream: No such file or directory
in file /var/www/****/dev/yii-1.1.3.r2247/framework/YiiBase.php at line 338
#0 CConsoleApplication->displayError(2, include(StatisticOnline.php): failed to open stream: No such file or directory, /var/www//dev/yii-1.1.3.r2247/framework/YiiBase.php, 338) called at [/var/www/ /dev/yii-1.1.3.r2247/framework/base/CErrorHandler.php:206] and much more
**** is not the real path
content of /protected/config/console.php
return array(
'basePath' => dirname(__FILE__).DIRECTORY_SEPARATOR.'..',
'name' => '**** Console',
// application components
'components' => array(
'db' => array(
'connectionString' => 'pgsql:host=192.168.2.149;port=5840;dbname=XYZ',
'emulatePrepare' => true,
'username' => 'user',
'password' => 'pass',
'charset' => 'utf8',
),
),
);
whats wrong or missing?
thanks
andy_s
(Arekandrei)
March 8, 2011, 5:30pm
2
You need to import models in your config:
'import'=>array(
'application.models.*',
),
or import a single model in your command class:
Yii::import('application.models.StatisticOnline', true); // "true" is to include a file immediately
corvus
(Yiiframework)
March 8, 2011, 5:33pm
3
andy_s:
You need to import models in your config:
'import'=>array(
'application.models.*',
),
or import a single model in your command class:
Yii::import('application.models.StatisticOnline', true); // "true" is to include a file immediately
argh so easy … i should stop working for today -.-
thank you