How to design the Controller for an Ajax(Extjs)-PHP Application?
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?
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.
精彩评论