我知道 symfony api 解释说 getMethod() 获取请求预期"方法,而 getRealMethod() 获取真实"请求方法,但我无法弄清楚预期"和真实"是什么意思.谁能告诉我?谢谢
I know the symfony api explain that getMethod() gets the request "intended" method and getRealMethod() gets the "real" request method but i can't figure out what "intended" and "real" means. Can anyone tell me? Thanks
推荐答案getRealMethod() 返回真实请求方法,而 getMethod()> 返回预期的请求方法,这意味着真正的请求方法是POST,但symfony将其他方法视为DELETE.
getRealMethod() returns the real request method, while getMethod() returns the intended request method, which means the real request method is POST but symfony treat as others like DELETE.
请看下面的例子:
<form method="post" action="..." > <input type="hidden" name="_method" value="DELETE" /> ... </form>真正的请求方法是POST,而getMethod()会返回DELETE.
The real request method is POST, while getMethod() will return DELETE.
检查来源:
/** * Gets the request "intended" method. * * If the X-HTTP-Method-Override header is set, and if the method is a POST, * then it is used to determine the "real" intended HTTP method. * * The _method request parameter can also be used to determine the HTTP method, * but only if enableHttpMethodParameterOverride() has been called. * * The method is always an uppercased string. * * @return string The request method * * @api * * @see getRealMethod */ public function getMethod() { if (null === $this->method) { $this->method = strtoupper($this->server->get('REQUEST_METHOD', 'GET')); if ('POST' === $this->method) { if ($method = $this->headers->get('X-HTTP-METHOD-OVERRIDE')) { $this->method = strtoupper($method); } elseif (self::$httpMethodParameterOverride) { $this->method = strtoupper($this->request->get('_method', $this->query->get('_method', 'POST'))); } } } return $this->method; } /** * Gets the "real" request method. * * @return string The request method * * @see getMethod */ public function getRealMethod() { return strtoupper($this->server->get('REQUEST_METHOD', 'GET')); }更多推荐
Symfony getMethod() 与 getRealMethod()
发布评论