I am having trouble debugging the console application, there seems to be some differences between some examples and the wiki
entries for console apps.
One point of confusion is whether to use "yiic test" or "cron.php test"
I created a simple command file extending CConsoleCommand
TestCommand.php:
<?php
class TestCommand extends CConsoleCommand {
public function run($args) {
// here we are doing what we need to do
// create a contact record
$c = new Contact;
$c->last_name = 'Harter';
$c->first_name = 'Bryan';
$c->contact_type = 2;
$c->save();
}
}
?>
cron.php script file:
#!/usr/bin/env php
<?php
// defined('YII_DEBUG') or define('YII_DEBUG',true);
// including Yii
require_once(dirname(__FILE__).'/../framework/yii.php');
// we'll use a separate config file
$config=dirname(__FILE__).'/config/cron.php';
// creating and running console application
Yii::createConsoleApplication($config)->run();
?>
Cronjob file cron.php:
<?php
return array(
// This path may be different. You can probably get it from `config/main.php`.
'basePath'=>dirname(__FILE__).DIRECTORY_SEPARATOR.'..',
'name'=>'Cron',
'preload'=>array('log'),
'import'=>array(
'application.components.*',
'application.models.*',
),
// We'll log cron messages to the separate files
'components'=>array(
'log'=>array(
'class'=>'CLogRouter',
'routes'=>array(
array(
'class'=>'CFileLogRoute',
'logFile'=>'cron.log',
'levels'=>'error, warning',
),
array(
'class'=>'CFileLogRoute',
'logFile'=>'cron_trace.log',
'levels'=>'trace',
),
),
),
// DB connection
'db'=>array(
'class' => 'CDbConnection',
'connectionString' => 'mysql:host=localhost;dbname=***',
'emulatePrepare' => true,
'username' => '*******',
'password' => '*******',
'charset' => 'utf8',
),
), //components
);
?>
I call the script from the protected folder ./cron.php test
I receive output of PHP Error[2]: include (EActiveRecordRelationBehavior.php): filed to open stream: No such file or directory
in file /usr/share/nginx/www/myapp/framework/YiiBase.php at line 421.
Seems to be an autoload problem from YiiBase.php
It seemed to find the model and other components, but I am uncertain what the problem is.
Anyone have any ideas what I am doing wrong or need to change?
Thanks!