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

  • 相关阅读:
    CentOS7 Install Consul
    CentOS6 Install kafka
    CentOS7 Install Shipyard
    zabbix_sender
    python mail
    CentOS6.8 RPM包安装快速zabbix22
    python与shell通过微信企业号发送消息
    zabbix监控之grafana
    linux查看进程(java)启动时间
    (ubuntu)安装配置jenkins(新版)
  • 原文地址:https://www.cnblogs.com/qinqiu/p/9041513.html
Copyright © 2011-2022 走看看