Symfony2 - how can I set custom CORS Headers?

前端 未结 4 526
情深已故
情深已故 2020-12-25 11:50

I want to set following Headers for TWIG Template from within my DefaultController:

header(\'Access-Control-Allow-Methods: GET, POST, OPTIONS\');
header(\'Ac         


        
4条回答
  •  甜味超标
    2020-12-25 12:06

    If you are using the render() method of the controller, then you can add the necessary headers like below because render() method returns a Response object:

    $response = $this->render('AppBundle:Post:index.html.twig', array('someArgs' => $someArgs));
    $response->headers->set('Content-Type', 'text/html');
    return $response;
    

提交回复
热议问题