Я использую класс команды для отправки почты cron. Как я могу настроить языковой стандарт для отправки электронной почты?Как установить locale в командный класс symfony2.1
$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('[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!');
} }
Великий решение. Спасибо! –
Отлично, может ли автор или кто-то подтвердить этот ответ, пожалуйста? –