International Developer Logo Last Updated 25.07.08 at 11.48
On Sale
This months front cover, click to see the table of contents.
Subscribe
 
TUTORIALS

Developing Three-Tier Web Applications with PHP


Daniel Winter   01.10.05


The Presentation Layer
The presentation layer takes a set of data variables from the application layer and formats its contents according to the user interface and graphic design of the application. This usually involves wrapping everything up in HTML with images, Flash movies, PDF files and other standard web documents. Although it is desirable to have a presentation layer that is completely independent of the application logic, a certain amount of logic will be required nonetheless.

Best practices are to ensure that such logic within the templates relates only to layout and design and not business rules. For instance, it is necessary when looping through database results in an HTML table to wrap each row with a <TR> tag. Thus it is necessary to use an IF statement of some kind to determine whether a wrap is due during the rendering of the HTML page. This is entirely appropriate (as well as unavoidable), although it would be a mistake to have the template check for a valid login, for instance. Instead, the application would pass a value to the template that indicates whether a login has been successful. The template would then display the relevant HTML code.


Step 1 - The Logical Application Model
In our example application we are going to build a simple management interface for an online training system. In order to keep the code examples readable, only a minimal set of tables, columns and functions will be used, although the principles remain the same for much larger data structures. As far as our application is concerned, we have four types of simple data objects that we are working with and each will form the basis of a PHP class. We have teachers, students, subjects and enrolments. The relationships between these objects are also simple. Students enrol for subjects and subjects are assigned a teacher. Students can enrol for multiple subjects but only one teacher can be assigned to each subject.




   Previous Page  1 2 3 4 5 6 7 8 9 10 ... Next Page   

HAVE YOUR SAY
This article is rated  Rate this article