codeigniter-restserver icon indicating copy to clipboard operation
codeigniter-restserver copied to clipboard

DELETE cannot retrive parameters.

Open liondev opened this issue 13 years ago • 5 comments

The DELETE method cannot retrive the parameters sent into a JSON string. POST, PUT Works fine but DELETE doesn't.

Content-Type : application/json

{ "id":"27" }

  public function index_delete(){


    $response = new stdClass();
    $id = $this->delete('id');

    $this->Employee_model->id = $id;
    $succeed = $this->Employee_model->delete_entry() > 0;

    $response->succeed = $succeed;
                               $response->id = $id;

    $this->response($response);
  }

$id = $this->delete('id'); returns FALSE.

liondev avatar Feb 12 '13 17:02 liondev

Hi,

I've had this problem too, so I edited the _parse_delete() method

protected function _parse_delete() { // Set up out DELETE variables (which shouldn't really exist, but sssh!) if (stripos($this->input->server('CONTENT_TYPE'), "application/xml") === FALSE) { $this->_delete_args = (array)json_decode(file_get_contents("php://input")); } else { $this->_delete_args = $this->format->_from_xml(file_get_contents("php://input")); } }

now I can send xml and json to a delete method

arrie1992 avatar Feb 28 '13 08:02 arrie1992

@arjanvdwal1992 thanks for the fix

*** edit *** my problem was, that I didn't send the data as JSON and that was why the _parse_delete() couldn't "find" the data. now that I'm passing JSON data, everything is working fine.

pkyeck avatar Mar 19 '13 14:03 pkyeck

@arjanvdwal1992 Thanks for the fix! Just ran into the same problem.

@pkyeck Did you not need this fix in the end? I couldn't get it to work otherwise.

hebime avatar Aug 06 '13 17:08 hebime

@Hebime yes, I did. but I also had to explicitly tell my ajax request to be json formatted:

$.ajax({
   beforeSend: function(xhr){
     xhr.setRequestHeader("Content-Type", "application/json");
   },
   url: "/data/block/2",
   type: "DELETE",
   dataType: "json",
   processData: false,
   data: JSON.stringify(data),
   success: function(data) {
      console.log(data);
   }
});

this is what I found with my commit saying that it fixed the problem ;)

pkyeck avatar Aug 06 '13 20:08 pkyeck

@pkyeck Ahh ok! Thanks for clarifying! :)

hebime avatar Aug 06 '13 21:08 hebime