我有一个打印“Hello World”的动作:
public function actionStart()
{
echo 'Hello World';
}
我将运行一个每分钟调用此操作的 cron 作业。
我怎么能用 yiic 做到这一点?
更新:
我创建控制台应用程序。我在 index.php 中有 cron.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();
和配置/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',
// …
),
),
);
和受保护的/commands/MyCommand.php:
<?php
class MyCommand extends CConsoleCommand
{
public function run($args)
{
$logs = Log::model()->findAll();
print_r($logs);
die();
}
}
当我运行这个:
$ ./protected/yiic my
我收到了这个错误:
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()
我该如何解决这个问题?