我尝试从命令提示符运行CRON。
我在webroot中创建了cron.php,这是index.php的副本,只需更改代码
App::uses('Dispatcher', 'Routing');
define('CRON_DISPATCHER',true);
if($argc == 2) {
$Dispatcher = new Dispatcher();
$Dispatcher->dispatch(new CakeRequest($argv[1]), new CakeResponse(array('charset' => Configure::read('App.encoding'))));
}
现在,我在命令提示符中使用
运行CRONE:/wamp/bin/php/php5.4.12/php.exe E:/wamp/www/warehouse/admin/webroot/cron.php cron/test.
在我的测试函数中我写了代码
$this->layout=null;
//Check the action is being invoked by the cron dispatcher
if (!defined('CRON_DISPATCHER')) { $this->redirect('/'); exit(); }
//$this->autoRender = false;
$my_file = 'E:/wamp/www/warehouse/admin/webroot/file.txt';
$handle = fopen($my_file, 'a') or die('Cannot open file: '.$my_file);
$data = 'New data line 1';
fwrite($handle, $data);
fclose();
echo "success";
exit;
但是它不是在webroot中创建文件,也没有显示任何错误。
有人能帮我吗?
我有同样的问题,我在控制器中添加了这个,它工作得很好
function beforeFilter() {
parent::beforeFilter();
$this->layout=null;
$this->Auth->Allow('cron_getCountryId');
}