【发布时间】:2013-12-04 09:48:55
【问题描述】:
我正在使用命令类来发送 cron 邮件。如何设置发送电子邮件的区域设置?
$this->getRequest()->setLocale('de');
就我而言,每个用户都有不同的语言环境。 如何在命令类中设置语言环境?
我尝试了$this->getRequest()->setLocale('de'); 并收到错误:
namespace IT\bBundle\Command;
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
class CronCommand extends ContainerAwareCommand {
protected function configure()
{
$this
->setName('send:emails')
->setDescription('Envio programado de emails');
}
protected function execute(InputInterface $input, OutputInterface $output)
{
$message = \Swift_Message::newInstance()
->setSubject('bla bla')
->setFrom('x@x.com')
->setTo('x@gmail.com')
->setCharset('UTF-8')
->setContentType('text/html')
->setBody($this->renderView('mainBundle:Email:default.html.twig'));
$this->getContainer()->get('mailer')->send($message);
$output->writeln('Enviado!');
} }
【问题讨论】:
标签: symfony-2.1