javascript - Cannot get body from DELETE request with Slim Framework -


i'm working in app using backbone.js , slim framework. issue here: need delete record executing mysql stored procedure receives, besides id of record delete, parameter execute business logic. problem receive id of record. $app->request()->getbody(); blank. here code:

/rest/folder/index.php

<?php require_once '../../vendors/slim/slim.php'; \slim\slim::registerautoloader(); $app = new \slim\slim();  $app -> get('/categories/', function() use ($app) {     require_once ('../../libs/auth.inc');     $auth = new authentication();     $user_id = $auth -> sessionauthenticate();      require_once ('categories.php');     $categories = new categories();     $categories -> getcategories($app, $user_id); });  $app -> post('/categories/', function() use ($app) {     require_once ('../../libs/auth.inc');     $auth = new authentication();     $user_id = $auth -> sessionauthenticate();      require_once ('categories.php');     $categories = new categories();     $categories -> savecategory($app, $user_id); });  $app -> put('/categories/:category_id', function($category_id) use ($app) {     require_once ('../../libs/auth.inc');     $auth = new authentication();     $user_id = $auth -> sessionauthenticate();      require_once ('categories.php');     $categories = new categories();     $categories -> savecategory($app, $user_id); });  $app -> delete('/categories/:category_id', function ($category_id) use ($app) {     require_once ('../../libs/auth.inc');     $auth = new authentication();     $user_id = $auth -> sessionauthenticate();      require_once('categories.php');     $categories = new categories();     $categories -> deletecategory($app, $user_id, $category_id); });  $app -> run(); 

here delete function on /rest/folder/categories.php

public function deletecategory($app, $user_id,$category_id) {     $requestbody = $app->request()->getbody();     $params = json_decode($requestbody, true);      $agreement_id = $params['agreement_id'];      $con = $this->conectardb();     $query = "call spd_categories($category_id,$agreement_id);";      //print_r($query);      $result = $this->con->query($query);         $this->con->close();     $app->status(200);     echo json_encode($result); } 

and here backbone delete function on /modules/folder/categoriesview.js

confirmdeleteform : function(event) {     event.preventdefault();     var category_id = $('#categories_select').select2("val");     var self=this;      this.category = this.categories.findwhere({'category_id':category_id});     var agreement_id = this.category.get('agreement_id');      $('#deletemodal').modal('hide');      this.category.destroy({         data: {             'agreement_id': agreement_id,         },         processdata : true,                  success: function(model, response) {              self.cleanform();             self.getcategories();         },         error: function(model, response) {             if (response.status == 500) {                 self.showerrormessage('se produjo un error en el servidor', 'error');             } else {                 self.showerrormessage(response.responsetext, 'atencion');             }         }     });  }, 

in model destroy tried add data: , headers: none of work.

is possible made?

thanks in advance.

update 1:

i've found this: slim v2 referred in first answer.

and this: backbone.js (backbone.router title)

this i'm trying now. can work, think way resolve issue i'm having.

update 2

still can figure out how this. so, because of almost-here deadline, changed database structure delete row id. keep trying after finishing project.

thanks.

have read this: http://docs.slimframework.com/routing/delete/#method-override?

unfortunately, modern browsers not provide native support http delete requests.

...if using backbone.js or command-line http client, may override http method using x-http-method-override header.


Comments

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - Bypass Geo Redirect for specific directories -

php - .htaccess mod_rewrite for dynamic url which has domain names -