Passing HTTP Request from Backbone.js to CodeIgniter to DB Passing HTTP Request from Backbone.js to CodeIgniter to DB codeigniter codeigniter

Passing HTTP Request from Backbone.js to CodeIgniter to DB


I had some problems with this as well. My solution:

$data = json_decode(file_get_contents('php://input'), true);$this->site_model->create($data);


You need to change this line under your Controller:

$this->post('title')

To

$this->input->post('title')

or actually you can use plain PHP for accessing your POST global variables, like $_POST['title'].

As reference, check the CodeIgniter's Input Class


I'm not too sure as to why your title param is not getting passed. I would recommend using Firebug or Chrome Inspector to check if the title param actually got sent. You can narrow down your debugging from there.

As for the URL, the RESTful way to do it would be to use MyApp/index.php/app/user/id" to manage a single user

EDIT

It looks like your request is sent fine. I would examine the post data. Why not print the post data and see what is received. My guess is PHP is not reading the JSON data correctly. You can use $decoded = json_decode($this->post('title')) to turn it into a php object.