Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sending text plain header in Symfony 2

Tags:

php

symfony

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?

like image 392
max Avatar asked Mar 26 '12 14:03

max


1 Answers

You need to add $response to render call

return $this->render($view, array(), $response);
like image 124
Inoryy Avatar answered Sep 29 '22 01:09

Inoryy