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);
    }

}
?>
#2

[eluser]Phil Sturgeon[/eluser]
Yeah that's how I did it with my RESTful Implementation.

They left it out as they are not commonly used for general web-applications. There is no way to even use those HTTP verbs without cURL.
#3

[eluser]mptre[/eluser]
Ah your blogpost on REST implementation got me inspired enough to start this project Smile Thanks for the feedback.
#4

[eluser]Unknown[/eluser]
For CodeIgniter2, change "parent::CI_Input();" to "parent::__construct();"




Theme © iAndrew 2016 - Forum software by © MyBB