only for RuBoard - do not distribute or recompile Previous Section Next Section

Formatting the Output

Our news site example follows a simple but structured format when displaying a page. Each page contains a number of stories that are all formatted the same way. First of all, the headline is displayed in a large type, followed by the photograph underneath on the left and then the story text on the right. The whole page is contained in a standard page template to preserve the site branding and consistency throughout.

Figure 26.2 shows the logical page structure that we will be using.

Figure 26.2. Logical page structure.
graphics/26fig02.gif

This kind of layout is extremely popular—how many sites do you visit regularly that have a menu bar at the left hand side or quick links at the top, with that outside navigation remaining in place no matter which page you are viewing?

Implementing a templated structure such as this from a page design is very simple. In the HTML source, you will find the <TD> where the main content cell begins. At this point, split the HTML into two files; the first half becoming the header file and the second, the footer. Whenever you display a page, show the header first, the page, and finally the footer.

Implementing the site with a header and footer template allows these template files to be easily changed if the site design is updated.

PHP provides two configuration options that appear useful in this situation. The directives auto_prepend_file and auto_append_file can be set on a per-directory basis to specify files that are included before or after any script is processed.

However this has some limitations. If you had any scripts that produce no output and send a redirect header such as

					
<? header("Location: destination.php"); ?>

				

the header and footer files would still be displayed and the redirect would fail because output has already been sent to the Web browser. This also causes problems with cookies and the built-in PHP 4 session management functions because a cookie header will not function correctly after any output has been sent to the Web browser.

only for RuBoard - do not distribute or recompile Previous Section Next Section