Welcome Guest, Not a member yet? Register   Sign In
Access DELETE and PUT data using the input library
#1

[eluser]mptre[/eluser]
Hi there!
I'm currently working on a RESTful API using Codeigniter. One thing that bothered me was the lack of accessing the passed arguments when the HTTP-method is set to either DELETE or PUT. So I wrote a simple extension to the existing input library. Any thoughts or feedback is much appreciated!

Code:
<?php
class MY_Input extends CI_Input {

    var $delete;
    var $put;

    function MY_Input() {
        parent::CI_Input();

        if ($this->server('REQUEST_METHOD') == 'DELETE') {
            parse_str(file_get_contents('php://input'), $this->delete);

            $this->delete = $this->_clean_input_data($this->delete);
        } elseif ($this->server('REQUEST_METHOD') == 'PUT') {
            parse_str(file_get_contents('php://input'), $this->put);

            $this->put = $this->_clean_input_data($this->put);
        }
    }

    function delete($index = '', $xss_clean = FALSE) {
        return $this->_fetch_from_array($this->delete, $index, $xss_clean);
    }

    function put($index = '', $xss_clean = FALSE) {
        return $this->_fetch_from_array($this->put, $index, $xss_clean);
    }

}
?>


Messages In This Thread
Access DELETE and PUT data using the input library - by El Forum - 12-28-2009, 06:03 PM
Access DELETE and PUT data using the input library - by El Forum - 12-29-2009, 07:56 AM
Access DELETE and PUT data using the input library - by El Forum - 12-29-2009, 08:05 AM
Access DELETE and PUT data using the input library - by El Forum - 01-18-2012, 04:59 AM



Theme © iAndrew 2016 - Forum software by © MyBB