Php 来自Symfony司令部的Swift邮件
我尝试使用Symfony命令从命令行发送Swift邮件。尽管我得到了以下例外Php 来自Symfony司令部的Swift邮件,php,symfony,swiftmailer,Php,Symfony,Swiftmailer,我尝试使用Symfony命令从命令行发送Swift邮件。尽管我得到了以下例外 Fatal error: Call to undefined method Symfony\Bundle\TwigBundle\Debug\TimedTwigE ngine::renderView() in ... 一个容器被添加到这个类中,这是我从命令中得到的containerawarecomand 函数的代码如下所示: private function sendViaEmail($content) { $
Fatal error: Call to undefined method Symfony\Bundle\TwigBundle\Debug\TimedTwigE
ngine::renderView() in ...
一个容器被添加到这个类中,这是我从命令中得到的containerawarecomand
函数的代码如下所示:
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(
正如您在代码中看到的,最后一行可能会失败,因为它最终到达那里。正如错误消息所说,
TwigEngine
中没有renderView
方法renderView()
是symfony base控制器类中的快捷方式:
namespace Symfony\Bundle\FrameworkBundle\Controller
class Controller extends ContainerAware
{
/**
* Returns a rendered view.
*
* @param string $view The view name
* @param array $parameters An array of parameters to pass to the view
*
* @return string The rendered view
*/
public function renderView($view, array $parameters = array())
{
return $this->container->get('templating')->render($view, $parameters);
}
}
在这里,您可以看到使用模板化服务渲染视图的正确方法
$this->container->get('templating')->render(
'BatchingBundle:Default:email.html.twig', array('content' => $content)
)