나는 cron 메일을 보내기 위해 명령 클래스를 사용하고 있습니다. 어떻게 이메일을 보낼 로케일을 설정할 수 있습니까?명령 클래스 symfony2.1에서 로케일을 설정하는 방법
$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('[email protected]')
->setTo('[email protected]')
->setCharset('UTF-8')
->setContentType('text/html')
->setBody($this->renderView('mainBundle:Email:default.html.twig'));
$this->getContainer()->get('mailer')->send($message);
$output->writeln('Enviado!');
} }
훌륭한 솔루션입니다. 고마워! –
우수, 저자 또는 누군가가이 답변을 확인해 주시겠습니까? –