#native_company# #native_desc#
#native_cta#

Cached Dynamic Modules

By JP
on July 30, 2000

In this article I will show how to use a modular system to create a website
that is constructed on the fly using dynamic modules, which for performance
sake can be cached if you want. Each module is a php script on its own, returning
html data to be included in the final html page.

Overview

  • php scripted modules that implement functionality (e.g. a style definition, menu or discussion board)
  • a parser that can construct the html page by reading input files, determining which modules to
    call and then combine output of the modules
  • files with specific extension (say .my) that specifiy html + calling tags for each module

Walkthrough

To demonstrate how it works, let’s see a file called hello.my:

<title>Hello world</title>

<my-style name=test>

hello world


If a request is being made for index.my, the webserver redirects
this request to the php parser, which just scans for <my- .. >
tags. It finds the ‘style’ tag, and looks for the module style.php in its module directory.
The file style.php is included and the function handle_style ($arglist)
is called, where $arglist is an associative array of all specified
parameters to the tag (here:


<?php $arglist[name] = "test"?>

).

The handle_style function must return a string containing html. How
the module determines the html doesn’t concern the system. Say, the handle_style
module returns <font face=Arial size=2 color=yellow> and the parser
includes this in the final html.

1
|
2
|
3
|
4
|
5
|
6