2012-03-26 40 views
6

Tôi có một hành động cho phép thông báo email hệ thống xem trước khách hàng và tôi muốn gửi tiêu đề text/plain cho các phiên bản thuần của email.Gửi tiêu đề văn bản thuần trong Symfony 2

Tôi đã cố gắng theo dõi phần Symfony docs : Requests and Responses in Symfony. Tuy nhiên, bộ điều khiển của tôi đang gửi một loại nội dung text/html bất kể tôi làm gì.

Đây là hành động của tôi:

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()); 
} 

Vì vậy, làm thế nào để gửi một văn bản tiêu đề đơn giản và nơi tôi đi sai?

Trả lời

13

Bạn cần phải thêm $ phản ứng để làm cho cuộc gọi

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

Brilliant, bạn đã lưu trong ngày của tôi. – max

Các vấn đề liên quan