【发布时间】:2017-02-01 13:45:54
【问题描述】:
我必须将动作模板呈现为一个简单的.txt 文件。
我该怎么做?除了使用Response 对象之外,还有其他方法吗?
使用Response 对象:
$content = $this->get('templating')->render(
'AppBundle:Company:accountBillingInvoice.txt.twig',
[
'invoice' => 'This is the invoice'
]
);
$response = new Response($content , 200);
$response->headers->set('Content-Type', 'text/plain');
【问题讨论】:
-
不,这是不对的,因为此响应将标头设置为
application/json,而我需要将标头设置为text/plain。 symfony.com/doc/current/components/… -
我很确定在我发布的答案中有如何进行文本和 json 响应的示例。阅读您链接到的示例和文档,并尝试理解它,而不是等待准备就绪。
-
我只是要求一种更简单的方法,我知道如何“手动”执行此操作:)