Symfony getMethod() против getRealMethod()
Я знаю, что API Symfony объясняют, что getMethod() получает метод "предназначенный" для запроса, а getRealMethod() получает "настоящий" метод запроса, но я не могу понять, что означает "предназначенный" и "настоящий". Кто-нибудь может сказать мне? Спасибо
1 ответ
getRealMethod()
возвращает метод реального запроса, в то время как getMethod()
возвращает предполагаемый метод запроса, что означает, что реальный метод запроса POST
но symfony относись как к другим как DELETE
,
Смотрите пример ниже:
<form method="post" action="..." >
<input type="hidden" name="_method" value="DELETE" />
...
</form>
Реальный метод запроса POST
, в то время как getMethod()
вернусь 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'));
}