Backbone JS and CodeIgniter REST Server Backbone JS and CodeIgniter REST Server codeigniter codeigniter

Backbone JS and CodeIgniter REST Server


You have to name your functions index_HTTPMETHOD. In your example it would be:

class RestApi extends REST_Controller {    // this will handle GET http://.../RestApi    function index_get() {    }    // additionally this will handle POST http://.../RestApi    function index_post() {    }    // and so forth    // if you want to POST to http://.../RestApi/somefunc    function somefunc_post() {    }}


the url-attribute of the model should match the server-side 'url' which returns the JSON that will make up the model's attributes. Backbone.js has default functionality to this, which is to match the model's collection url with it's id attribute. The collection url requirement can be foregone by overriding the urlRoot -function, in order to operate model's outside of collections.

If you want to be independent of the id -attribute as well, you sould override the url -attribute/function to provide your own url that matches to the model on the server, like this:

url: 'path/to/my/model'

or

url: function() { // Define the url as a function of some model properties  var path = this.model_root + '/' + 'some_other_url_fragment/' + this.chosen_model_identifier;  return path; }