加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

php – 来自Symfony Command的Swift邮件

发布时间:2020-12-13 13:33:23 所属栏目:PHP教程 来源:网络整理
导读:我尝试使用Symfony命令从命令行发送 Swift邮件.虽然我得到以下例外. Fatal error: Call to undefined method SymfonyBundleTwigBundleDebugTimedTwigEngine::renderView() in ... 一个容器被添加到这个类中,这是我从ContainerAwareCommand命令中获得的
我尝试使用Symfony命令从命令行发送 Swift邮件.虽然我得到以下例外.
Fatal error: Call to undefined method SymfonyBundleTwigBundleDebugTimedTwigE
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 SymfonyBundleFrameworkBundleController

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)
)

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读