When backbone.js saves the model to the server, it sends a PUT request. How do I handle them with php? How to take content sent using put request and save them in the database?
Here is another example:
$ values = json_decode (file_get_contents ('php: // input'), true);
see php docs for an example http://php.net/manual/en/features.file-upload.put-method.php
from php.net:
<?php /* PUT data comes in on the stdin stream */ $putdata = fopen("php://input", "r"); /* Open a file for writing */ $fp = fopen("myputfile.ext", "w"); /* Read the data 1 KB at a time and write to the file */ while ($data = fread($putdata, 1024)) fwrite($fp, $data); /* Close the streams */ fclose($fp); fclose($putdata); ?>
you can leave the fwrite part out when you want to save the data in the database.
Backbone.emulateHTTP = true;
If you want to work with an outdated web server that does not support the default REST / HTTP Backbones approach, you can enable Backbone.emulateHTTP. Setting this parameter will fake PUT and DELETE requests using HTTP POST and pass them using the _method parameter. Setting this option also sets the X-HTTP-Method-Override header using the true method.
After that, execute your own sync function in your model: http://documentcloud.github.com/backbone/#Sync
sync