Symfony2 模板无需请求 [英] Symfony2 Templating without request

查看:19
本文介绍了Symfony2 模板无需请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从 Symfony2 中的 ContainerAwareCommand 发送电子邮件.但是当电子邮件模板通过以下方式呈现时,我会收到此异常:

I'm trying to send an email from a ContainerAwareCommand in Symfony2. But I get this exception when the email template is render by:

$body = $this->templating->render($template, $data);

例外:

 ("You cannot create a service ("templating.helper.assets") of an inactive scope ("request").") 

我在github上发现这个helper需要请求对象.有人知道如何实例化 Request 对象吗?

I found in github that this helper need the request object. Anybody knows how can I to instance the Request object?

推荐答案

既然没有请求,就需要像这样直接调用模板服务:

Since you don't have a request, you need to call the templating service directly like this:

$this->container->get('templating')->render($template, $data);

这篇关于Symfony2 模板无需请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆