Zend - The PHP Company




Miscellaneous

Add Code


Nested modules/requires  

Type: code fragment
Added by: opido
Entered: 10/03/2000
Last modified: 08/12/1999
Rating: *** (5 votes)
Views: 5350
You can nest require('page.php') based on variables, this can lead some very dynamic application/modules that can all run from a single interface...


////////////////////////////////////////////////////////////
//                                                        //
// Obviously this code could be cleaned up,               //
// and applied in a realistc manner, such as an intranet  //
// or administrative interface for something or another...//
//                                                        //
////////////////////////////////////////////////////////////
INDEX.PHP
------------------------------------------------
<?
require("module_a.php");
require(
"module_b.php");
?>
------------------------------------------------


MODULE_A.PHP
------------------------------------------------
<?
if($module == 'a1'){
    require(
'module_a1.php');
    }
elseif(
$module == 'a2'){
    require(
'module_a2.php');
    }
else{
?> 
<p>PLEASE SELECT A SUB-MODULE:</p>
<p><a href="<? echo $PHP_SELF?>?module=a1">a1</a> | <a href="<? echo $PHP_SELF?>?module=a2">a2</a></p>
<?
    
}
?>
------------------------------------------------


MODULE_B.PHP
------------------------------------------------
<?
if($module == 'b1'){
    require(
'module_b1.php');
    }
elseif(
$module == 'b2'){
    require(
'module_b2.php');
    }
else{
?> 
<p>PLEASE SELECT A SUB-MODULE:</p>
<p><a href="<? echo $PHP_SELF?>?module=b1">b1</a> | <a href="<? echo $PHP_SELF?>?module=b2">b2</a></p>
<?
    
}
?>
------------------------------------------------




Usage Example




Rate This Script





Search



This Category All Categories