-3
我必须将操作的模板呈现为简单的.txt
文件。Symfony:如何将模板呈现为简单的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');
检查此答案,http://stackoverflow.com/a/27693540/1857533 – Gustek
不,这是不正确的,因为此响应将头设置为'application/json',而我需要将头设置为'text/plain' 。 http://symfony.com/doc/current/components/http_foundation.html#creating-a-json-response – Aerendir
我非常肯定,在我发布的答案中,有如何做文本和json响应的例子。阅读您链接的示例和文档,并尝试理解它,而不是等待准备就绪。 – Gustek