所以我的页面在页面的不同部分有很多包含调用。其中大多数都包含某种函数来捕获任何$ _GET变量。所有这些都可以正常工作,除了我的导航文件,当我尝试抓取任何GET变量时,它不会返回任何内容。
nav.php
<? require_once("config.php"); require_once("functions.php"); ?>
<div id="nav">
<ul>
<? initializeMainNav( $_GET['page'] ); ?>
</ul>
</div>
在function.php里面
function initializeMainNav( $curPage )
{
// array ( slug, name ) of navigation items
$nav = array(
array( "", "Home" ),
array( "case_studies", "Investment Case Studies" ),
array( "current_inv", "Current Investments" ),
array( "about", "About MDIG" ),
array( "management", "Management" ),
array( "news", "News" ),
array( "services", "Services" ) );
// Print out each nav item, and highlight the current page nav item
for( $i = 0; $i < count( $nav ); $i++ ) {
echo " <li><a ";
if( $nav[$i][0] == $curPage )
echo "class=\"active\" ";
echo " href=\"?page=" . $nav[$i][0] . "\">" . $nav[$i][1] . "</a></li> ";
}
}
$ _ GET ['page']总是返回空,即使它适用于页面的所有其他部分。你们看到我做错了什么?
编辑:
index.php其中HEADER
是一个定义路径的常量var,位于config.php
<? require_once("config.php"); require_once("functions.php"); ?>
<? include(HEADER); ?>
<body>
<div id="wrapper">
<div id="logo">
<a href="<? echo DOMAIN; ?>"><img src="<? echo IMAGES; ?>/logo.png" alt="<? echo COMPANY; ?>"></a>
</div>
<div class="clear"></div>
<? include(NAV); ?>
<div id="content_wrapper">
<!-- Find and display appropriate page -->
<? displayPage( $_GET['page'] ); ?>
</div>
<div class="clear"></div>
<? include(FOOTER); ?>
</div>
</body>
</html>
答案 0 :(得分:0)
我知道这并不一定能给你答案,为什么它不起作用,但是如下所示:
的functions.php
function echoMainNav($curPage)
{
echo '<div id="nav"><ul>';
echo initializeMainNav( $curPage );
echo '</ul></div>';
}
somepage.php
<? require_once("config.php"); require_once("functions.php"); ?>
<? include(HEADER); ?>
<body>
<div id="wrapper">
<div id="logo">
<a href="<? echo DOMAIN; ?>"><img src="<? echo IMAGES; ?>/logo.png" alt="<? echo COMPANY; ?>"></a>
</div>
<div class="clear"></div>
<? echoMainNav( $_GET['page'] ); ?>
<div id="content_wrapper">
<!-- Find and display appropriate page -->
<? displayPage( $_GET['page'] ); ?>
</div>
<div class="clear"></div>
<? include(FOOTER); ?>
</div>
</body>
</html>
或者更好:
templates.php
define('TEMPLATES_MAIN_NAV', '<div id="nav"><ul>%s</ul></div>');
的functions.php
function getMainNav($curPage)
{
return sprintf(TEMPLATES_MAIN_NAV, initializeMainNav( $curPage ) );
}
somepage.php
<?= getMainNav($_GET['page']); ?>