PHP, though having it’s limitations, has grown into a vast and robust language of choice by many developers, including myself. PHP5 when initially released back in 2006, offered a true Object Oriented experience. Yet to this day, I still find that many PHP develpers are not using the true capabilities that PHP has to offer. Frameworking in PHP is not only ideal, but offers a great amount of flexibility and power to drive any system. Granted, not all sites will need a robust framework, having a psuedo framework in place is still idea.
The days of inter-twining PHP and HTML should be something of the past, yet I find many still do it. Even without creating a J2EE Framework, a small psuedo framework could be something that will help you rapidly deploy the site in a matter of days to a week. Like most mainstream software engineering is concerned, you have several layers. You will have the view or graphical interface layer, the database abstraction layer, and the processing layer. Properly setting up classes and objects to handle each layer can greatly improve speed, reliability, and ease of trouble shooting.
Mixing PHP and HTML makes the code hard to read, hard to understand, and sends you on a needle in a haystack hunt trying to find the break. Creating a templating layer that will read a template and combined with the processing layer can help you easily find a break when it comes to visual. You basically know it will be in one of those components. If you are smart, you will incorporate a debug mode to all of your classes that you can verbose out all information that is being processed and how it is being processed. The only layer that should ever talk to the visual layer is the constructor page and the content processing layer. Even then they really don’t need to talk. The visual object or layer should only have to deal with the visual aspects. The content processing layer should only have to work with the database layer to get the content ready to be inserted into the visual layer.
This will provide a basic framework that you can use through out all sites that will make it easier to deploy and rapidly deploy sites that do not need the power of an actual framework. The typical core objects I usually have are the template class, and the content class. Though the content class will usually be broken up into it’s own classes and subclasses based on the function of the particular page or data being processed. The template class is basically just that. It will grab a template, insert the necessary data, and return. Lately I have been using PDO as a the database layer. If you have ready my previous post on a better way of using a database object, then you already know that I initiate the database object in an autoload page, and then make that object readily available to all classes. It cuts database tunnels to only one, and i believe is more efficient on resources. Not to mention it makes things a whole lot easier.
It provides flexibility in changing templates on the fly, keeps the data where it belongs, and it makes the code easier to read.































































