我需要從symfony2的命令類渲染一個樹枝模板。從symfony2的命令行發送郵件
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!');
}
}
但是,當我執行命令php app/console send:emails
我收到以下錯誤:
Fatal error: Call to undefined method
IT\bBundle\Command\CronCommand::renderView()
我如何渲染視圖?
只是一個腳註:如果你打算髮送批量電子郵件,這是不是做到這一點。如果它只是一段時間,它會沒事的。 – transilvlad