A Basic Dynamic Module


Let's say you want to create a dynamic ContactUs module that displays either e-mail or mailing address information. You want the following URLs to work:

  • modules.php?name=ContactUs&which=mail should display mailing address info.

  • modules.php?name=ContactUs&which=email should display e-mail info.

  • modules.php?name=ContactUs should display links for either e-mail or mailing address, linking back to the ContactUs module with the appropriate parameter.

Here's a file that does that:

 <?php if (!eregi("modules.php", $_SERVER['PHP_SELF'])) {     die ("You can't access this file directly..."); } $module_name = basename(dirname(__FILE__)); $index = 1; function snailmail() {     global $module_name;     include("header.php");     OpenTable();     echo "Our address is:";     CloseTable();     include("footer.php"); } function email() {     global $module_name;     include("header.php");     OpenTable();     echo "Our e-mail address is:";     CloseTable();     include("footer.php"); } function MainMenu() {     global $module_name;     include("header.php");     OpenTable();     echo "Which do you want?<br><br>";     echo "<ul>";     echo "<li><a href=\"modules.php?name=$module_name&amp;which=email\">E-Mail Address</a>";     echo "<li><a href=\"modules.php?name=$module_name&amp;which=mail\">Mailing Address</a>";     echo "</ul>";     CloseTable();     include("footer.php"); } switch($which) {     default:     MainMenu();     break;     case "mail":     snailmail();     break;     case "email":     email();     break; } ?> 

Notice some common bits of each function:

  • They begin by declaring the variable $module_name as a global. This is required for all functions.

  • They include the pages header.php and footer.php. This is required: header.php must be included before the module outputs any text, and footer.php must be included as the last thing the module does.

  • They use the OpenTable() and CloseTable() functions, which draw the themed elements of the PHP-Nuke site. This is required, and all of the module's content must appear in between these two function calls.



    PHP-Nuke Garage
    PHP-Nuke Garage
    ISBN: 0131855166
    EAN: 2147483647
    Year: 2006
    Pages: 235
    Authors: Don Jones

    flylib.com © 2008-2017.
    If you may any questions please contact us: flylib@qtcs.net