我编写了一个报告套件,我有一个特定的报告来构建一个CSV文件.通过浏览器按需提供此文件不是问题,但我需要能够每晚构建此CSV文件,并通过电子邮件发送链接以便能够下载它.
基本上,我需要能够用symfony任务替换特定的动作,通过cron运行.那么如何从symfony任务中获取应用程序/模块上下文?其次,我如何从symfony任务调用SwiftMailer库?
我正在使用symfony v1.4.4和PHP v.5.2.13.
小智 5
在任务的configure()函数中,您需要定义任务中涉及的应用程序:
$this->addOptions(array(
new sfCommandOption('application', null, sfCommandOption::PARAMETER_REQUIRED, 'The application name','frontend'),
new sfCommandOption('env', null, sfCommandOption::PARAMETER_REQUIRED, 'The environment', 'dev'),
new sfCommandOption('connection', null, sfCommandOption::PARAMETER_REQUIRED, 'The connection name', 'doctrine'),
));
Run Code Online (Sandbox Code Playgroud)
然后你必须在execute()函数中创建上下文:
sfContext::createInstance($this->configuration);
Run Code Online (Sandbox Code Playgroud)
最后你可以很容易地调用Swift:
$this->getMailer()->composeAndSend($sender,$dest, $subject, $mailBody);
Run Code Online (Sandbox Code Playgroud)