2

我正在启动一个新的 Web 应用程序,我有这个非常愚蠢的担忧,我想我会向你们所有人澄清。

此应用程序将是一个单页 Web 应用程序,将以 Html、JS/Flex 作为前端和 PHP 作为后端进行开发。所以我有两个选择

  1. 将所有应用程序逻辑保留在客户端,即(JS/Flex),并使用 PHP 仅将数据输入和输出到数据库。
  2. 仅对 UI 使用 JS/Flex,并将所有应用程序逻辑保留在 PHP 中,将作为独立服务使用。

两者都有优点和缺点

  • 如果我选择第一个选项,应用程序的用户体验将是流畅的。(因为这涉及非常少的客户端服务器交互)
  • 如果我选择第二个选项,应用程序逻辑将存在于 PHP 中,稍后我可以将其公开为 API,以防我希望其他人使用相同的 API 并构建自定义应用程序。

但我无法就两者的优缺点进行争论并最终确定一个。请帮忙,希望您在开发生涯中一定遇到过类似的问题。

提前致谢!

4

2 回答 2

2

我建议并更喜欢这样做option 2,原因如下 1. 正如您所说,您可以稍后公开 API。2. 由于所有应用程序逻辑都将由 PHP 处理,因此将更加安全。

于 2013-07-19T05:51:08.427 回答
1

There are lots of design patterns however since you are interested in the possibility of making API's later the most appropriate for you would be a form of your option 2.

Use JS/Flex only for UI and keep all the application logic in PHP, which will be consumed as independent services.

Simply make a front end using one of the following technologies for single page application front end UI:

Difficulty

Then make all your business logic into RESTful API calls written in PHP or Python or any other backend language.

If these services allow for full CRUD and not just Read I recommend using OAuth to secure your services to only allow authorized users to Create, Update, and Delete. You can just use an OAuth PHP library.

The reason for this is it allows you to create any other applications and just have to rebuild the UI and not have to remake the business logic in every language (C, C++, objective C, C#, Python, PHP, JavaScript, Ruby, etc.). Then when you release the API to the public they will call your OAuth service with a valid username and password (given by the user) and will be able to make a rich full featured application because you have now eating your own dog food. This is a very important concept, although it might take you longer to develop you won't have to re-architect and thereby re-develop or re-factor a lot of code.

于 2013-07-19T20:32:34.883 回答