如何为Ajax(Extjs)-PHP应用程序设计Controller?

应用程序正在使用ExtJs,(Json),PHP和MySQL进行设计。 超过一半的逻辑/模型将在服务器端。 虽然很大一部分逻辑与ExtJs Frontend有关。 这主要是单页应用程序,因此传统的MVC前端控制器/路由在这里不起作用。 我仍然想设计一个管理与服务器交互的php Controller。 怎么做到最好?</ p>
</ div>

展开原文

原文

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?

1个回答



我建议根据“网络服务”来考虑服务器。 从本质上讲,您的ExtJS前端代码将是应用程序,而您的后端“Web服务”只会提供获取和存储数据的方法。</ p>

基本上它会是这样的 :</ p>


  • 基于ExtJS的“UI图层”</ li>
  • 基于JavaScript的“控制器图层”与UI图层一起使用</ li>
    < li>基于PHP的“服务层”</ li>
  • UI层与控制器层交互,然后控制器层与服务层交互</ li>
    </ ul>

    服务层基本上与任何典型的PHP Web应用程序相同:它包含数据验证,输入过滤,数据库查询,所有常见的东西。 主要的区别在于,不是使用PHP生成然后发送到浏览器的HTML,服务层只会将结果序列化为JSON。</ p>

    JS中的控制器层 代码将对服务执行Ajax请求。 它将处理JSON结果,并告诉UI层它应该显示什么。 它还包含处理来自UI的事件的方法。</ p>

    UI层的行为类似于模板引擎或HTML代码。 它将显示从控制器层分配给它的数据,它将调用控制器层中的函数来处理按下按钮等事件。</ p>
    </ div>

展开原文

原文

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:

  • ExtJS based "UI layer"
  • JavaScript based "controller layer" works with the UI layer
  • PHP based "service layer"
  • The UI layer interacts with the controller layer, which then interacts with the service layer

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.

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐