Looking for a good way to organize a web app
I am doing a simple Web application which works more or less like this: (simplified)
Module Selection page: When the user selects a module, the module page appears开发者_Go百科
Module page: Contains buttons for various items. Click on a button and a small AJAX script retrieves the item for a Module Handler
Module Handler: simple PHP script called from the module page through AJAX. Does the job by querying the database and checking permissions
My problem is with the issue of the first item: When the user lands on the Module page, the first item should be already displayed, but all the code to retrieve the item is in the Module handler.
I could of course import the Module Handler inside the Module page and query the functions directly in PHP to get my first item, but it feels a bit dirty to include the handler, and then call to it.
Is there a better way of doing this?
If you are looking for a good design pattern for a web application, look no further :
http://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93controller
The Model View Controller is a well tested one and various frameworks use it.
In your case, the modules are the controllers, the pages are the views and the handlers are the models.
Well i can simply suggest let your first view be loaded, be blank. Just do a include to the default module you want to handle. That way, the view will be just playing like a router. Rather then routing it to the request, it will just import it and use it.
精彩评论