博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
getMasterRequest VS getCurrentRequest?
阅读量:5151 次
发布时间:2019-06-13

本文共 1475 字,大约阅读时间需要 4 分钟。

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

转载于:https://www.cnblogs.com/qinqiu/p/9041513.html

你可能感兴趣的文章