I have an action that lets the customer preview system email messages and i want to send a text/plain
header for the plaintext versions of the emails.
I tried to follow the Symfony docs : Requests and Responses in Symfony section. However my controller is sending a text/html
content-type no matter what i do.
This is my action:
function showAction($action = null, $format = null){
$locale = $this->get('session')->getLocale();
$format = $this->getRequest()->get("format");
$format = isset($format) ? $format : 'html';
if ($format === 'text'){
$response = new Response();
$response->headers->set('Content-Type', 'text/plain');
$response->sendHeaders();
}
$view = sprintf('MyBundle:Email:%s.%s.%s.twig',
$action,$locale,$format);
return $this->render($view, array());
}
So how do I send a text plain header and where am I going wrong?
您需要在渲染调用中添加$ response
return $this->render($view, array(), $response);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.