Symfony2. I can't set Content-Length header

2019-08-06 07:40发布

问题:

i am new on Simfony and I am trying to set a Content-Length header in my response.

This is my controller action:

public function homepageAction() {

   $content= $this>renderView('AcmeBlogBundle:Pages/homepage:homepage_content.html.twig');

   $response= new Response();

   $response->setContent($content);

   $response->headers->set('Content-Length: 1736233495'); // value added manually

   return $response;

} // homepage

i obtain an error 500 internal server error.

回答1:

Did you try to $response->headers->set('Content-Length', 1736233495); ?

EDIT : Documentation



回答2:

Maybe the "-" missing in the "$this>renderView" part ?