When I started with PHP years ago, it was moreso a toy than anything else. With this attitude came many terrible coding habits that I have since had to relearn as my code is being used more and more in production environments. At first, I just started separating things out into different files, using more include()'s, and indenting my files so that they looked pretty 😃. Eventually, though, the need for completely reusable, stable, and secure code became paramount, and my coding style evolved to match.
I began utilizing data encapsulation, OO programming, and ended up with code that was much more managable. Although I've always been a proponent of separating presentation from logic, the following article inspired me to look even deeper at reusability, scalability, and security:
http://devzone.zend.com/node/view/id/763
The thing that stuck with me from this article the most, the thing that made me rethink all of my current designs, was the Multi-Tiered Design Model. Sure, I had classed-out my database functions, had them nice and separate, and of course had a templating system always in use, but other than that my code was granted permission to 'run free', as it were.
Inspired by the piece, I proceeded to develop the following design model that would work well for several of my new projects:
1- Browser, E-mail client, Mobile Device
2- Presentation Layer - Markup information, apply templates
3- Communication Query Layer - Logical and Translative layer. Takes 'communication queries' incoming or outgoing, formulates an appropriate response, and then forwards it to the appropriate layer. ]
ex) from: Logic & Learning Layer - Send this data of type dataType to user.
ex) from: ditto (above) - Retrieve data of types dataTypesArray from user
ex) from: Presentation Layer - Send this data from user input to the Logic and Learning layer.
4- Logic & Learning Layer - Serves multiple functions. Firstly, it provides a security barrier between the audience and data. It also directs information to and from the proper pieces of code, and is where any optimization, log, statistic, or other intelligent code would be.
5- Data Interaction Layer [Manipulate data models, manipulate data, etc ]
6- Data Storage Layer [Interact with database, files, etc]
This model makes coding much easier for me and makes my applications much more scalable, and user-device independent, among other great benefits.
It provides more work in the beginning - coding out many generic functions, creating a whole system for a communication query layer, and re-doing any current modules that perform specific functions to operate primarily in layers 4 & 5, leaving data storage and communication with the client to other layers.
Anyways, I hope to get feedback on the following questions:
1) What do you think is the best overall multi-tiered design model?
2) Could one design model work best for a group of similar applications? ( One for blogs, one for CMS's, etc ) or does each need its own individual design model?
3) And of course, how could I improve my design model?
I can't end this post without commenting on how awesome and generous this community has been, and how many times I have been amazed to find answers to all my questions by searching around on these seasoned boards!