I have an action that prints "Hello World":
public function actionStart()
{
echo 'Hello World';
}
I will to run a cron job that calls this action every minute.
How I can do this with yiic ?
UPDATE:
I create console app. I have cron.php inside index.php:
<?php
defined('YII_DEBUG') or define('YII_DEBUG',true);
// including Yii
require_once('framework/yii.php');
// we'll use a separate config file
$configFile='protected/config/c.php';
// creating and running console application
Yii::createConsoleApplication($configFile)->run();
and config/c.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.models.*',
'application.components.*',
),
// 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',
),
),
),
// Your DB connection
'db'=>array(
'class'=>'CDbConnection',
// …
),
),
);
and protected/commands/MyCommand.php:
<?php
class MyCommand extends CConsoleCommand
{
public function run($args)
{
$logs = Log::model()->findAll();
print_r($logs);
die();
}
}
when I run this:
$ ./protected/yiic my
I got this error:
PHP Error[2]: include(Log.php): failed to open stream: No such file or directory
in file /path/to/app/folder/framework/YiiBase.php at line 427
#0 /path/to/app/folder/framework/YiiBase.php(427): autoload()
#1 unknown(0): autoload()
#2 /path/to/app/folder/protected/commands/MyCommand.php(6): spl_autoload_call()
#3 /path/to/app/folder/framework/console/CConsoleCommandRunner.php(71): MyCommand->run()
#4 /path/to/app/folder/framework/console/CConsoleApplication.php(92): CConsoleCommandRunner->run()
#5 /path/to/app/folder/framework/base/CApplication.php(180): CConsoleApplication->processRequest()
#6 /path/to/app/folder/framework/yiic.php(33): CConsoleApplication->run()
#7 /path/to/app/folder/protected/yiic.php(7): require_once()
#8 /path/to/app/folder/protected/yiic(3): require_once()
How I can fix this?