我希望我的导航栏图标在用户位于某个页面时(例如在 instagram 等)上改变颜色。这就是我尝试过的 - bottomBar.php:if ($page == 'friends') { $theme = 'link_friendsWall_active'; $theme2 = 'link_index'; $theme3 = 'link_trophypage'; $theme4 = 'link_selfpage';} else if ($page == 'index') { $theme = 'link_friendsWall'; $theme2 = 'link_index_active'; $theme3 = 'link_trophypage'; $theme4 = 'link_selfpage';} else if ($page == 'trophy') { $theme = 'link_friendsWall'; $theme2 = 'link_index'; $theme3 = 'link_trophypage_active'; $theme4 = 'link_selfpage';} else if ($page == 'profile') { $theme = 'link_friendsWall'; $theme2 = 'link_index'; $theme3 = 'link_trophypage'; $theme4 = 'link_selfpage_active';}$page 是指在 index.php(作为索引)、friendsWall.php(作为朋友)等文件中定义的变量,其中包含 bottom_menu。主题定义的变量是在 css 中设置样式的类。然后在我的底部菜单中,我调用了这些变量:<div class="bottom_menu"> <li><a class="<?=$theme?>" href="includes/handlers/friends_link.php"> <i class="fas fa-user-friends"></i> </a></li> <li><a class="<?=$theme2?>" href="index.php"> <i class="fas fa-users "></i> </a></li> <li><a href="#"> <i class="fas fa-plus-circle"></i> </a></li> <li><a class="<?=$theme3?>" href="trophyPage.php"> <i class="fas fa-trophy"></i> </a></li> <li><a class="<?=$theme4?>" href="myProfile.php"> <img class='img_bottom_bar' src="<?php echo $user['profile_pic']; ?>" width="30px" height="30px" border-radius="20px"> </a></li></div>我的问题是该网站没有从其他页面读取变量 $page 。索引.php: session_start(); include("includes/header.php"); include("includes/bottomBar.php"); include("includes/classes/User.php"); include("includes/classes/Post.php"); $page = 'index';
3 回答
米琪卡哇伊
TA贡献1998条经验 获得超6个赞
变量在$page使用后定义
session_start();
$page = 'index'; // definition
include("includes/header.php");
include("includes/bottomBar.php"); // Using
include("includes/classes/User.php");
include("includes/classes/Post.php");
千巷猫影
TA贡献1829条经验 获得超7个赞
正如评论中指出的那样,您在定义变量bottomBar.php
之前$page
包括在内。所以,什么时候bottomBar.php
被渲染,$page
仍然是未定义的!
因此,只需在 include$page
之前定义bottomBar.php
:
$page = 'index'; include("includes/bottomBar.php");
- 3 回答
- 0 关注
- 130 浏览
添加回答
举报
0/150
提交
取消