如何为 Ajax(Extjs)-PHP 应用程序设计控制器?
该应用程序是使用 ExtJs、(Json)、PHP 和 MySQL 设计的。超过一半的逻辑/模型将位于服务器端。虽然重要的逻辑块是与 ExtJs 前端相关的。这主要是一个单页应用程序,因此传统的 MVC 前端控制器/路由在这里不起作用。我仍然想设计一个 php 控制器来管理与服务器的交互。如何最好地做到这一点?
The application is being designed with ExtJs, (Json), PHP, and MySQL. More than half of the logic/Model will be on the server side. While significant chunk of the logic is with the ExtJs Frontend. This is mostly a Single Page Application, so the traditional MVC Front End Controller/Routing does not work here. I would still like to design a php Controller that manages the interactions with the server. How best to do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我建议将服务器视为“网络服务”。本质上,您的 ExtJS 前端代码将是应用程序,而您的后端“Web 服务”将仅提供获取和存储数据的方法。
基本上是这样的:
服务层本质上与任何典型的 PHP Web 应用程序相同:它将包含数据验证、输入过滤、数据库查询以及所有常用的内容。主要区别在于,服务层不会使用 PHP 生成 HTML 然后发送到浏览器,而是仅将结果序列化为 JSON。
JS 代码中的控制器层将对服务执行 Ajax 请求。它将处理 JSON 结果,并告诉 UI 层应该显示什么。它还包含处理来自 UI 的事件的方法。
UI 层的行为有点像模板引擎或 HTML 代码。它将显示从控制器层分配给它的数据,并调用控制器层中的函数来处理按下按钮等事件。
I would suggest thinking of the server in terms of a "web service". Essentially, your ExtJS front-end code would be the application, and your back-end "web service" would only provide ways to fetch and store data.
Basically it would be something like this:
The service layer would essentially be the same as in any typical PHP web app: It would contain data validation, input filtering, database queries, all the usual stuff. The main difference would be that instead of using PHP to generate HTML that would then be sent to the browser, the service layer would only serialize the results into JSON.
The controller layer in the JS code would perform Ajax requests to the services. It would process the JSON results, and tell the UI layer what it should display. It would also contain methods which handle events from the UI.
The UI layer would simply act sort of like a template engine or your HTML code. It would display data assigned to it from the controller layer, and it would call functions in the controller layer to handle events like pressing buttons.