Submitting a plain text header in Symfony 2

I have an action that allows a client to view system emails and I want to send a text/plain header for text versions of emails.

I tried to execute the Symfony docs: Requests and Responses in Symfony section . However, my controller sends 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 header and where am I mistaken?

+6
source share
1 answer

You need to add $ response to render call

 return $this->render($view, array(), $response); 
+13
source

Source: https://habr.com/ru/post/911680/


All Articles