php接收delete参数,laravel 如何接收 http delete 请求的参数?Input::get()不行

我觉得这个问题你应该去探讨 php 如何获取delete请求的吧。如果PHP可以通过像$_POST同样的$_DELETE方式来获取的话那就自然你可以在Action里通过这种方式来获取(但是据我所知好像没有)。

所以你就得想其他的方式了,分析一下PHP的$_SERVER这个全局变量然后结合file_get_contents('php://input');这个方法。

http://php.net/manual/zh/reser ... r.php

楼上说用 Input::getContent() 这个方法,好像我没找到这个方法。

Here is some code which may be helpful for others wanting to handle PUT and DELETE params. You are able to set $_PUT and $_DELETE via $GLOBALS[], but they will not be directly accessible in functions unless declared global or accessed via $GLOBALS[]. To get around this, I've made a simple class for reading GET/POST/PUT/DELETE request arguments. This also populates $_REQUEST with PUT/DELETE params.

This class will parse the PUT/DELETE params and support GET/POST as well.

class Params {

private $params = Array();

public function __construct() {

$this->_parseParams();

}

/**

* @brief Lookup request params

* @param string $name Name of the argument to lookup

* @param mixed $default Default value to return if argument is missing

* @returns The value from the GET/POST/PUT/DELETE value, or $default if not set

*/

public function get($name, $default = null) {

if (isset($this->params[$name])) {

return $this->params[$name];

} else {

return $default;

}

}

private function _parseParams() {

$method = $_SERVER['REQUEST_METHOD'];

if ($method == "PUT" || $method == "DELETE") {

parse_str(file_get_contents('php://input'), $this->params);

$GLOBALS["_{$method}"] = $this->params;

// Add these request vars into _REQUEST, mimicing default behavior, PUT/DELETE will override existing COOKIE/GET vars

$_REQUEST = $this->params + $_REQUEST;

} else if ($method == "GET") {

$this->params = $_GET;

} else if ($method == "POST") {

$this->params = $_POST;

}

}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值