zoukankan      html  css  js  c++  java
  • getMasterRequest VS getCurrentRequest?

    When dealing with multiple requests, the non master request comes from internal requests. Usually from twig in the form of

    {{ render(controller('foo')) }}

    When the second request is created, only the request format and locale are copied to the new instance. Therefore, any data you would expect to come from the user, will not be available. This includes request parameters, ip address, and any HTTP headers.

    In most situation, you will only need to deal with the current request. But, to answer your question, any time you need data coming from the user, you will require the master request. An example would be using the users IP address to pre-select a CountryType form control.

    When using getMasterRequest()->getClientIp() you would be given the IP address of the user (something like 209.58.130.174). When calling it on the non master you will be given the localhost/loopback IP (127.0.0.1). There aren't really any methods that will return null, they simply return different information about how the request was created.

     The master request is the one that comes from the original user; the subrequest is the one that you do internally — either with the forward() method of HttpKernel — or by the forward() helper of the framework's Controller class — or {% render ... %} in Twig.

    ===
    https://stackoverflow.com/questions/36218809/requeststack-when-should-i-use-getmasterrequest-rather-than-getcurrentrequest

  • 相关阅读:
    IO-BufferedInputStream
    IO-FileOutputStream
    IO-FileWriter
    关于我
    并不知道取什么标题
    颓废日记
    笔记合集
    Codeforces Round #690 (Div. 3) 简要题解
    Codeforces 1470B Strange Definition
    Codeforces 1466E Apollo versus Pan
  • 原文地址:https://www.cnblogs.com/qinqiu/p/9041513.html
Copyright © 2011-2022 走看看