我应该使用MVC无论在客户端和服务器? [英] Should I use MVC both on client and server?

查看:103
本文介绍了我应该使用MVC无论在客户端和服务器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经决定使用MVC模式在我的网站。所以,现在我使用Backbone.js的框架在我的网站。
我的网站上的所有操作都是 ajaxy ,所以服务器只从数据库获取数据,并且将数据保存到数据库中。

I've decided to use MVC Pattern on my site. So, now I use Backbone.js framework on my site. All actions on my site are ajaxy, so server only gets data from db, and saves data to db.

我是否需要在服务器端使用MVC吗?它的所有复杂,不是吗?

Do I need to use MVC on the server side too? It's complicating all, isn't it?

或者我可能会使用MVC在客户端,并有简单的服务器API,只获取/保存数据,并使得一些小型服务器的工作吗?

Or I may use MVC on client side, and have simple server api, that only fetches/saves data and makes some small server job?

UPD:我知道我应该使用模式服务器端。但什么是查看有关服务器端 - ?如果我渲染用JavaScript的所有信息

UPD: I understand that I should use Models on server side. But what are Views for on server side - if I render all information with javascript?

所以,它是一个很好的模式,即服务器端仅适用于原始数据 - 模式 - 它总是返回 JSON ,与HTML的标记和相关浏览其他的事情没有关系

So, Is it a good pattern, that server side works only with raw data - models - it always returns json, and has no relation with html-markup and other things related to Views ?

推荐答案

没有,你不这样做的需要以使用服务器端,但它的将会的提供帮助组织/分离应用和业务逻辑。根据应用程序的规模,这可能极大帮助的未来。

No, you don't need to use it server-side, but it will help with organization / separation of application and business logic. Depending on the scale of your application, that could help tremendously in the future.

关键是只是确保你组织你的后端code好,否则你会最终有一个整体和/或难以维持codeBase的。

The key is just making sure you organize your backend code well, otherwise you will end up with a monolithic and/or difficult-to-maintain codebase.

编辑回应OP的编辑:结果
服务器端的意见将包含您的HTML和可能会或可能不会让对服务器的请求任何JavaScript。这是假设你实际上是用PHP构建一个用户导航到的页面。

Edit in response to OP's edit:
Server-side views would contain your HTML and any JavaScript that may or may not make requests to the server. This assumes that you are actually using PHP to build the pages that a user navigates to.

如果您有建立自己使用AJAX请求一个静态的html页面,那么你的不会的需要在所有使用服务器端的看法。你的控制器就更有可能成为输出JSON数据。如果是这种情况,它不会使模型和控制器的任何用处不大。

If you have a static html page that builds itself using AJAX requests, then you may not need to use server-side views at all. Your controllers would more than likely be outputting JSON data. If this is the case, it doesn't make models and controllers any less useful.

这篇关于我应该使用MVC无论在客户端和服务器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆