I'm having issues handing data from Backbone to a CodeIgniter application... After calling Backbone's save() or sync() methods and inspecting the request headers in Chrome Tools, it appears that Backbone sends data to the server using a Request Payload and not the standard Form Data approach that jQuery, and standard HTML forms submit with.
If I enable Backbone.emulateJSON(), the post is sent via Form Data and I'm able to retrieve the data in $this->input->post('model') as expected. I can then call json_decode() on that data and be on-my-way – However, this will break my implementation of CodeIgniter's Validation library. I store my validation rules in separate files and behind the scenes they expect data to reside in $this->input->post(), not $this->input->post('model');
I have looked into using Phil Sturgeon's Restserver library. It appears that it will allow me to remove Backbone.emulateHTTP() by handling PUT and DELETE requests. However, I would still be required to call $this->post('model'), validation would still be broken, and in fact, validation isn't even supported for the PUT and DELETE requests with this library!
I'm beginning to think CodeIgniter's had the biscuit and will not support my needy front-end requirements. I've been sticking with CodeIgniter because I'm used to it's architecture by this point and Datamapper ORM is so wonderful.
Suggestions on how to proceed? I'm open to entire backend framework swapping if your suggestion comes with an elegant RESTful implementation that works with Backbone by default, has a strong ORM, and extensive validation / XSS libraries. Or if you can solve my CodeIgniter dilemma, that works too.
Check Phil Sturgeon codeigniter restfull controller implementation.
https://github.com/philsturgeon/codeigniter-restserver
It won't be necessary to move to Slim or other framework if you use this rest controller.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With