我已经编写了一个模型和控制器方法,我想通过 cron 作业使用它,但是经过调查,我似乎必须将其作为带有控制台/命令的 shell 来执行。我已经阅读了一些不同的 SO 帖子和手册,但这一切都超出了我的想象。
这就是我迄今为止所拥有的——几乎从我的模型和控制器中所拥有的。有人可以给我一些关于如何让它工作的指示吗?预先感谢。
**** 编辑 - 现在可以使用 ****
<?php
App::uses('Shell', 'Console');
App::uses('CakeEmail', 'Network/Email');
class OldClaimsShell extends AppShell {
// Include the ExpesesCLaim mdel
public $uses = array('ExpenseClaim');
/**
* When fired it checks for claims over 7 days that are still "submitted" and have therefore not been dealt with. Function has to be called MAIN - see cake docs
*/
public function main() {
// Find all claims with status "submitted" that are older than 7 days
$answer = $this->ExpenseClaim->haveClaimsOlderThan7Days();
//debug($answer);
if ($answer === true) {
$Email = new CakeEmail();
$Email->domain('www.xxx.co.uk');
$Email->template('oldExpenseClaimReminder');
$Email->to('xxx@xxx.co.uk');
$Email->from('xx@xx.co.uk');
$Email->subject('There are outstanding claims over 7 days old - Please Review');
$Email->viewVars(array('link' => 'http://xxx.xxx.co.uk'));
$Email->emailFormat('both');
$Email->send();
//$this->out('Email sent');
}
}
}
?>
根据答案和评论修改了问题 - 尽管 Cron 没有,但现在可以使用。将在另一个问题中探讨这一点。