Symfony getMethod() 与 getRealMethod()

编程入门 行业动态 更新时间:2024-10-28 13:15:44
本文介绍了Symfony getMethod() 与 getRealMethod()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我知道 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()

本文发布于:2023-10-10 22:57:36,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1480000.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:Symfony   getMethod   getRealMethod

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!