Microsoft Word - Core PHP Programming Using PHP to Build Dynamic Web Sites

(singke) #1

content unique to the page, the stuff that comes before it, and the stuff that comes after it.
This could be hard to maintain, however. Some of the HTML is in one file, some in
another. If nothing else you'll need to flip between two editor windows.


Consider for a moment a Web page as an object—that is, in an object-oriented way. On
the surface, a Web page is a pair of HTML tags containing HEAD tags and BODY tags.
Regardless of the design or content of the page, these tags must exist, and inside them
will be placed further tags. Inside the BODY tags a table can be placed for controlling the
layout of the page. Inside the cells of the table are either links to other pages on the site or
some content unique to the page.


FreeEnergy is a system that attempts to encapsulate major pieces of each page into files
to be included on demand. Before I proceed, I want to state my motivations clearly. My
first concern when developing a Web site is that it be correct and of the highest quality.
Second is that it may be developed and maintained in minimal time. After these needs are
addressed, I consider performance. Performance is considered last because of the
relatively cheap cost of faster hardware. Moore's law suggests that eighteen months from
now, CPU speed and memory capacity will have doubled for the same price. This
doubling costs nothing but time. Also, experience has shown that a small minority of
code contributes to a majority of the time spent processing. These small sections can be
optimized later, leaving the rest of the code to be written as clearly as possible.


The FreeEnergy system uses more calls to include than you'd find where you are
simply making a few includes at the top of your pages. Hits to the file system do take
longer than function calls, of course. You could place everything you might need in one
large file and include it on every page, but you will face digging through that large file
when you need to change anything. A trade has been made between the performance of
the application and the time it takes to develop and maintain it.


I called this system FreeEnergy because it seems to draw power from the environment
that PHP provides. The include function in PHP is quite unique and central to
FreeEnergy, especially the allowance for naming a script with a variable. The content
unique to a page is called a screen. The screen name is passed to a single PHP script,
which references the screen name in a large array that matches the screen to
corresponding layout and navigation modules.


The FreeEnergy system breaks Web pages into five modules: action, layout, navigation,
screen, and utility. Action modules perform some sort of write function to a database, a
file, or possibly to the network. Only one action module executes during a request, and
they are executed before the screen module. An action module may override the screen
module named in the request. This is helpful in cases where an action module is
attempting to process a form and the submitted data are incomplete or otherwise
unsatisfactory. Action modules never send data directly to the screen. Instead, they add
messages to a stack to be popped later by the layout module. It is possible that an action
module will send header information, so it's important that no output be produced.

Free download pdf