Symfony2: in Twig, pass Request with Render function

前端 未结 3 933
感情败类
感情败类 2020-12-17 15:27

I understand that using {% render() %} automatically forces a new request object to be sent, but im curious if theres a way to pass in the originating request a

3条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-17 16:11

    Since Symfony 2.4 you can access the original request via the request_stack. This avoids the need to create a new method parameter.

    function exampleAction() {
      $request = $this->get('request_stack')->getMasterRequest();
      //do something
    }
    

    Use this carefully as it makes your sub-requests incompatible with ESIs/reverse proxies (where a sub-request is also a master request) http://symfony.com/blog/new-in-symfony-2-4-the-request-stack

提交回复
热议问题