将 CodeIgniter (PHP) 与 Backbonejs 混合
我只是想问,同时使用 PHP 后端 MVC 结构和前端 js MVC 结构混合是否有意义?
我的问题来自于在 CodeIgniter 中构建一个 Web 应用程序,我已经开始使用 websockets 和 nodejs,所以我与前端的很多交互甚至不接触 php。目前,更改数据库中内容的唯一方法是通过 ajax 调用通过 CI。
有什么建议以及如何创建和维护这两种 MVC 结构吗?或者应该避免这种情况。
I just want to ask, does it make sense to use both a PHP backend MVC structure, mixed with a front end js MVC structure?
My question arises from building a web application in CodeIgniter, I've begun working with websockets and nodejs so a lot of my interactions to the front end don't even touch php. Currently though the only way to change content in my database is to go through CI via ajax calls.
Is there any advice and how to create and maintain both MVC structures? or should this be avoided.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
正如您已经说过的:CodeIgniter 是一个 MVC 框架。当您使用 BackboneJS 时,您将不需要 CI 的 VIEW 部分,并且也不需要那么多的 MODEL 部分。
您可以使用 CodeIgniter 作为简单的 API 后端,作为前端和数据库之间的中间人(有非常好的用于 CI 的 xmlrpc 库!),或者您可以使用特定于 REST 的框架,如 Recess (http://www.recessframework.org/),试试这个:https://stackoverflow.com/questions/238125/ best-framework-for-php-and-creation-of-restful-based-web-services
简短回答:您的 php 后端将仅充当 API 提供程序,供BackboneJS,因此您可以使用任何框架,只要它适合您的需求 - CodeIgniter 似乎就能做到这一点。
提示:您可以从 CodeIgniter 中删除 API 不需要的库和帮助程序。
As you already said: CodeIgniter is a MVC framework. As you're using BackboneJS you won't need the VIEW-part of CI and the MODEL-part won't be needed that much.
You could use CodeIgniter as a simple API backend that handles as a middleman between your frontend and the database (there are very good xmlrpc libraries for CI out there!) or you could go for a REST-specific framework like Recess (http://www.recessframework.org/), try this: https://stackoverflow.com/questions/238125/best-framework-for-php-and-creation-of-restful-based-web-services
Short answer: your php-backend would just serve as a API-provider which is used by BackboneJS, so you could use any framework as long as it fits your needs - and CodeIgniter seems to do that.
Tip: you can just delete the libraries and helpers from CodeIgniter that you won't need for you API.