Handling PUT/DELETE arguments in PHP

前端 未结 6 1259
盖世英雄少女心
盖世英雄少女心 2020-11-30 21:30

I am working on my REST client library for CodeIgniter and I am struggling to work out how to send PUT and DELETE arguments in PHP.

In a few places I have seen peopl

6条回答
  •  暖寄归人
    2020-11-30 22:21

    This is my version of the DELETE for CI. It accepts GET-style arguments for the DELETE, even same name arguments, i.e.: GET /some/url?id=1&id=2&id=3

    protected function _parse_delete()
    {
        $query = $_SERVER['QUERY_STRING'];
        if ( !empty( $query ) )
        {
            foreach( explode('&', $query ) as $param )
            {
                list($k, $v) = explode('=', $param);
                $k = urldecode($k);
                $v = urldecode($v);
                if ( isset( $this->_delete_args[$k] ) )
                {
                    if ( is_scalar( $this->_delete_args[$k] ) )
                    {
                        $this->_delete_args[$k] = array( $this->_delete_args[$k] );
                    }
                    $this->_delete_args[$k][] = $v ;
                }
                else
                {
                    $this->_delete_args[$k] = $v;
                }
            }
        }
    }
    

提交回复
热议问题