我尝试使用 Symfony 命令从命令行发送 Swift 邮件。虽然我得到以下异常。
Fatal error: Call to undefined method Symfony\Bundle\TwigBundle\Debug\TimedTwigE
ngine::renderView() in ...
一个容器被添加到这个类中,这是我从创建的命令中获得的ContainerAwareCommand
该函数的代码如下所示:
private function sendViaEmail($content) {
$message = \Swift_Message::newInstance()
->setSubject('Hello Email')
->setFrom('123@gmail.com')
->setTo('123@gmail.com')
->setBody(
$this->container->get('templating')->renderView(
'BatchingBundle:Default:email.html.twig', array('content' => $content)
)
);
$this->get('mailer')->send($message);
}
更新
发生异常的行是$this->container->get('templating')->renderView(
正如您在代码中看到的那样,最后一行可能会失败,因为它最终会到达那里。