Putting It All Together
To use the PHP functions described above and otherwise make the inheritance system work, you will need to add a standard include file to each page. This standard include file sets up the basic inheritance system, loads default settings, loads other libraries you expect to use on every page, and loads placeholders you can use elsewhere to override or enhance the default settings. While not strictly necessary, using a standard include file such as the one in this article's downloadable code
adds power and flexibility to the OO file system. You will also find details and source to a small working site in the sample code.
You could specifically add a standard include file by writing the code to load it at the top of each page, or add it generically by writing the code at the top of each header template. The included code demonstrates both methods. Despite the extra line per file, it's useful to put the include line in each page, because you can then modify the defaults before the page template starts to display. Simply put this at the top of each page:
<? include("std.inc"); ?>
Then, between this line and the line to include the page header, you can change variables used by the header, and otherwise modify the style before it begins to display. You'd typically use such modifications to set the page title, or set other parameters used by the main template.
You'll find some small extras included with the source. These are not necessary to implement the OO file system, but you may find them useful. A brief description of each follows:
- Menus: Three files implement a system for side menus: The side_menu.inc file is generic code to handle a menu definition. The file menu_style.inc tells the code what HTML you want to display for each type of menu item, while menu.inc contains the main menu definition. You can easily define the menu contents per-folder or per-section on a large site. The default HTML style uses CSS-friendly divs to make applying themes easy, and the sample site includes a simple CSS style that demonstrates how to apply a theme to the menu items.
- Automatic Forwarding: In forward.inc you'll find functions to direct a browser automatically from one place to another. This is particularly useful if you want to move content without breaking incoming links from other sites. Combine this with replacements for the default 404 document's "Page not found" message and a bit of string manipulation, and you can redirect entire sections with little effort.
- Modification Time: This is useful if you want each page to show the last time it was changed, without having to do so manually. Just include mod_time.inc in your template, and call its mod_time() function where you want the information to appear.
I have other components available for this system too, such as an image gallery and a basic content management system. Feel free to contact me for more information.