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

  • 相关阅读:
    1 外部JavaScript
    1 外部JavaScript
    蓝桥杯:位运算
    Java为什么要配置环境变量
    java数组静态复制和动态复制越界问题
    Dijkstra算法java实现
    离散二元关系实验java实现
    Java中字符串split() 的使用方法
    用java编程实现集合的交、并、差和补运算
    61根据字符出现频率排序(451)
  • 原文地址:https://www.cnblogs.com/qinqiu/p/9041513.html
Copyright © 2011-2022 走看看