EllisLab text mark
Advanced Search
     
Access DELETE and PUT data using the input library
Posted: 28 December 2009 09:03 PM   [ Ignore ]
Joined: 2009-12-28
10 posts

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!

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

}
?> 
 
Posted: 29 December 2009 10:56 AM   [ Ignore ]   [ # 1 ]   [ Rating: 0 ]
Avatar
Joined: 2007-06-11
2985 posts

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.

 Signature 

————————
Blog | Twitter | GitHub | BitBucket
————————-
PyroCMS - open source modular CMS built with CodeIgniter
PancakeApp - Simple, hosted invoicing/w project management

 
Posted: 29 December 2009 11:05 AM   [ Ignore ]   [ # 2 ]   [ Rating: 0 ]
Joined: 2009-12-28
10 posts

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

 
Posted: 18 January 2012 07:59 AM   [ Ignore ]   [ # 3 ]   [ Rating: 0 ]
Joined: 2010-11-15
3 posts

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