Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

PHP Build a Simple PHP Application Creating the Menu and Footer Adding Active States to the Navigation

Zerui Ma
Zerui Ma
5,422 Points

Bug not mentioned in the video

After setting up $section value in shirts and contact page, it is true that these pages are working exactly as expected, but if you switch the index page, you'll see a messed up header.

I inspected the element, found the cause of the bug: $section is undefined in index page. So I give the value like

$section = "index";

I think it's important to include this in the video

1 Answer

Hi Zerui,

It's not mentioned in the video because possibly it wasn't discovered until afterwards. The fix is included in the project files though. I think it should be mentioned in the Teacher's Notes.

My solution was to do this:

<li class="shirts<?php if ( isset($section) && $section == "shirts") { echo " on"; } ?>"><a href="shirts.php">Shirts</a></li>
<li class="contact<?php if ( isset($section) && $section == "contact") { echo " on"; } ?>"><a href="contact.php">Contact</a></li>
<li class="cart"><a href="#">Shopping Cart</a></li>

By checking if it's set first you don't have to worry about setting the $section variable on pages that aren't going to use it.