dougu2006 2015-05-22 22:05
浏览 32
已采纳

从另一个PHP页面更改PHP值

I'm trying to add a navbar to all the pages I have, the navbar is a PHP file, and it works for me, but I also wanna put the active navbar button, I tried my best but it didn't work...

This is my 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-->

and I put this in the other pages:

    <?php

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

?>

Sorry for the noob question but I searched so far but didn't find anything. Thanks in advance

展开全部

  • 写回答

2条回答 默认 最新

  • dousi6701 2015-05-22 22:11
    关注

    Hello, i think you have everything good, you just need ton inverse the line ^^

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

    and remove

    <?php
    $active="";
    ?>
    

    on the other file

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)
编辑
预览

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部