DescriptionThis page was written using a set of PHP classes that encapsulate most of the HTML. If one studies how the web protocol works one quickly realizes that the heart of server-to-browser communication is the Document Object Model, or DOM. The DOM is object based. HTML plays the role of delivering string representations of objects to web browsers.Simply stated, its all about objects! So why not construct web pages by playing with objects and automate the process of constructing almost all of the HTML just before the page is delivered? What you see here is a page that is constructed and delivered in just that way. Practically all of the HTML is encapsulated, or hidden, during the page's construction. During the construction of this page the following HTML was used:
The approach taken here is very simple. All low level formating of text is handled with a Cascading Style Sheet. All high level formating of the page is handled with objects. The right hand column illustrates some of the code that generates this page. A web page is looked at simply as an object. As you read the description below, follow the implementation of the description in the right hand column. What is a web page? It is a Page object composed of a Head object and a Body object. Head methods are used to give the page a title that appears above on the marque, and to associate a cascading style sheet to the page. The first item inserted into the body object is a header object, the header at the top of the page. Look at the rest of the page, it is a two-column table. It is represented with a table object. The table is the full width of the window and has a ten pixel padding around each cell. The table cells have been given equal width, although that will probably be overwridden by the fixed format in the second column, and both columns are vertically aligned to the top. The text you see down the left column is inserted in cell (1, 1) up until the bulletted listing, whcih is represented with a Listing object. Bullets are placed into the listing object with calls to it listEntry method. After the Lisitng is formed, it is inserted in the cell and followed by more text. Hyperlinks are encapsulated with the HLink class. Hyperlink formating is achieved with the style sheet. The second column header is placed in the top of the second column, followwed by the formating of the code within pre tags. Eventually, the table is inserted into the body and the very last statement, $P->render() constructs the HTML representation of the objects and transmits it to a web browser. This approach has been under development since 2002. In 2003 the initial version of the Table class was developed and provided insight into the use of classes. During my Spring 2005 sabbatical, with the availability of PHP 5 and its improved object model, the current set of classes were developed. I found the approach to be extremely productive. I am a software developer, I am comfortable looking at code, not HTML. The more I use this approach the more comfortable I feel with where it is leading me. |
Code Sample#!C:/php/php-cgi
<?php
include_once("phpClasses/Page.inc");
include_once("phpClasses/Constants.inc");
include_once("phpClasses/Layout.inc");
$H = new Head();
$B = new Body();
$P = new Page($H, $B);
$H->title("A Sample PHP Class Page");
$H->css("sample.css");
$B->insert(
new Header(1, "<center>PHP Class Sample Page</center>"));
$T = new Table();
$T->tableProperties
(array("cellpadding"=>10, "width"=>"100%"));
$T->cellProperties(1, 1,
array("width"=>"50%", "valign"=>"top"));
$T->cellProperties(1, 2,
array("width"=>"50%", "valign"=>"top"));
$T->cell(1, 1, new Header(3, "Description"));
$T->cell(1, 1, "
This page was written using a set of PHP classes t ...
If one studies how the web protocol works one quic ...
The DOM is object based. HTML plays the role of d ...
Simply stated, its all about objects! So why not c ...
What you see here is a page that is constructed an ...
During the construction of this page the following ...
");
$L = new Listing();
$L->listEntry("<b>center</b>: A center tag is included ...
$L->listEntry("<b>bold/strong</b>: Bold and italic tag ...
$L->listEntry("<b>p</b>: Paragraph tags are used to se ...
$L->listEntry("<b>pre</b>: The pre tag is used to illu ...
$T->cell(1, 1, $L);
$T->cell(1, 1, "The HTML encapsulating classes are ");
$T->cell(1, 1, new
HLink("documented",
"http://www.cs.scranton.edu/~doc/php/output/"));
$T->cell(1, 1, " using phpdoc. Links to the d ...
$T->cell(1, 1, new HLink("Home Page", "index.cgi"));
$T->cell(1, 1, ". The include_once statement make ...
...
$T->cell(1, 2, new Header(3, "Code Sample"));
$T->cell(1, 2, "
<pre>
...
</pre>
");
$B->insert($T);
$P->render();
?>
|