Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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.