php – 来自Symfony Command的Swift邮件

发布时间:2022-04-30 发布网站:脚本宝典
脚本宝典收集整理的这篇文章主要介绍了php – 来自Symfony Command的Swift邮件脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
我尝试使用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(

正如你在代码中看到的那样,最后一行可能会失败,直到它最终到达那里.

正如错误消息所述,TwigEngine中没有renderView方法. renderView()是symfony基类控制器类中的一个快捷方式:
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)
)

脚本宝典总结

以上是脚本宝典为你收集整理的php – 来自Symfony Command的Swift邮件全部内容,希望文章能够帮你解决php – 来自Symfony Command的Swift邮件所遇到的问题。

如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典推荐好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。