• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Access DELETE and PUT data using the input library

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!

class MY_Input extends CI_Input {

    var $delete;
    var $put;

    function MY_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);


[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.

Ah your blogpost on REST implementation got me inspired enough to start this project Smile Thanks for the feedback.

For CodeIgniter2, change "parent::CI_Input();" to "parent::__construct();"

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.