Question

Ive been using MVC frameworks for a while now, and have been through Cake, Codeignitor and have now settled on Laravel (thanks to Jeffrey Way over at nettuts). I heard great things about Backbone so I did some of the tutorials and really liked it.

I have a few questions, I hope someone can answer

  1. In quite a few bb tutorials the controllers are always restful, can bb only work with restful controllers?

  2. I'm really stuck in the paradigm of controller -> view. Now with backbone from what I've gathered doesn't use views at all but templates. Is it possible to still serve a view as normal and then client side create a collection from the rendered view? That way I'm still using a mvc backend as normal but also integrating backbone to keep track of my data on the frontend. if this is possible, is is bad form?

Was it helpful?

Solution

In quite a few bb tutorials the controllers are always restful, can bb only work with restful controllers?

Backbone includes default code to work easily with restful servers. However, that functionality is easily overridable to work with various servers or back ends. There are adapters for localStorage, for example. So if your server is non-rest, you can still work with it, but you'll have to write some code to adapt accordingly.

Backbone Views are sort of hybrid views/controllers and templates handle the actual HTML. Generally, if you want to bootstrap a collection in the browser, you need to make the data available as JSON. Rendering HTML on the server and then trying to extract data from that and hydrate a collection is jumping through extra, awkward hoops that people usually try to avoid. What you can do is include your JSON data inside a <script> tag and have it parsed into javascript objects and used with backbone in the browser.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top