简体   繁体   中英

Backbone.js and codeIgniter

I'm using the codeigniter Framework to use my servers side logic, and I want to use backbonejs to manage the client side logic.

I read a lot about it and there are many ways to achieve this, I thought using the following design:

  • In CI , keep only one view for each application. This will be a placeholder for the content that will be pushed by BackboneJS . The BackboneJS will be loaded from this page.
  • In BackboneJS , manage all the application client side , and query the CI controllers (that might call CI models if needed) to fetch the dynamic content.

What is the best way to use them both? Does my design breaks the MVC design somehow?

Premise: I use Yii instead of CI but I think they work in a similar way.

I have a index view in Yii which contains the main HTML structure of my app (menu, sidebar, main content, etc.) and a main controller which manage the REST requests, using Yii's model to retrieve information.

On the client Backbone take care of all, each route fire a request to the REST-like api and the views are finally rendered by the client with the data returned from the server in JSON format.

I don't know if this is the better way, but after some struggling I get it to work and I'm quite happy about it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM