从另一个PHP页面

时间:2015-05-23 06:05:16

标签: php html twitter-bootstrap

我试图在我拥有的所有页面上添加一个导航栏,导航栏是一个PHP文件,它适用于我,但我也想放置有效的导航栏按钮,我尽力而为但它没有& #39; t work ...

这是我的navbar.php:

<nav class="navbar navbar-default navbar-fixed-top">
<!--Brand Starts-->

<?php
$active="";
?>

<a class="navbar-brand pull-right animation-sliding-l-r" href="#">
    <img src="images/logo.png" alt="logo"/>
</a>

<!--Brand Ends-->
<button type="button" class="navbar-toggle pull-left collapsed btn navbar-btn btn-block" data-toggle="collapse"
        data-target="#navbar-collapse">
    <i class="fa fa-anchor fa-lg"></i>
</button>

<!--Navbar Buttons Start-->
<div class="collapse navbar-collapse" id="navbar-collapse">
    <ul class="nav navbar-nav">
        <li class="<?php if ($active=='Home') {echo "active";} else {  } ?>"><a href='home.php'><i class='fa fa-home fa-lg'></i> Home</a></li>
        <li class="<?php if ($active=='Store') {echo "active";} else {  } ?>"><a href='store.php'><i class='fa fa-shopping-cart fa-lg'></i> Store</a></li>
        <li class="<?php if ($active=='Report') {echo "active";} else {  } ?>"><a href='report.php'><i class='fa fa-flag fa-lg'></i> Report</a></li>
        <li class="<?php if ($active=='Moderator Application') {echo "active";} else {  } ?>"><a href='moderator-application.php'><i class='fa fa-user-plus fa-lg'></i> Mod Application</a></li>
        <li class="<?php if ($active=='About') {echo "active";} else {  } ?>"><a href='about.php'><i class='fa fa-book fa-lg'></i> About</a></li>
    </ul>
</div>
<!--Navbar Buttons End-->

我把它放在其他页面中:

    <?php

    include("includes/navbar.php");
    $active = "Store";

?>

对于noob问题很抱歉,但我搜索到目前为止但没有找到任何结果。 提前致谢

2 个答案:

答案 0 :(得分:3)

您好, 我认为你有一切都很好,你只需要反转线^^

<?php


$active = "Store";
include("includes/navbar.php");

?>

并删除

<?php
$active="";
?>

在另一个文件

答案 1 :(得分:1)

由于您首先包含文件而未声明变量将其他页面代码更改为以下内容,因此未获得适当的结果

<?php
$active = "Store";
include("includes/navbar.php");

从其他文件中删除$active="";,因为它会覆盖页面值

&GT;