我希望我的導(dǎo)航欄圖標(biāo)在用戶位于某個頁面時(例如在 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 中設(shè)置樣式的類。然后在我的底部菜單中,我調(diào)用了這些變量:<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>我的問題是該網(wǎng)站沒有從其他頁面讀取變量 $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貢獻(xiàn)1998條經(jīng)驗 獲得超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貢獻(xiàn)1829條經(jīng)驗 獲得超7個贊
正如評論中指出的那樣,您在定義變量bottomBar.php
之前$page
包括在內(nèi)。所以,什么時候bottomBar.php
被渲染,$page
仍然是未定義的!
因此,只需在 include$page
之前定義bottomBar.php
:
$page = 'index'; include("includes/bottomBar.php");
- 3 回答
- 0 關(guān)注
- 153 瀏覽
添加回答
舉報
0/150
提交
取消