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!

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 Enhancing a Simple PHP Application Cleaning URLs with Subfolders Introducing Subfolders

shirts.php is not displaying anything, code-review needed

Hello Coders,

Can you please review my code below? There should be an error somewhere and I can't find it...

    require_once(ROOT_PATH . "inc/products.php"); 

$pageTitle = "Mike's Full Catalog of Shirts";
$section = "shirts";
include(ROOT_PATH . 'inc/header.php'); 

        <div class="section shirts page">

            <div class="wrapper">

                <h1>Mike&rsquo;s Full Catalog of Shirts</h1>

                <ul class="products">
                    <?php foreach($products as $product_id => $product) { 
                            echo get_list_view_html($product_id,$product);



<?php include(ROOT_PATH . 'inc/footer.php') ?>

With the following htaccess:

RewriteEngine On
RewriteRule ^shirts/$ shirts/shirts.php

Please note I can not do /shirts/shirts.php because it doesn't work with MAMP.

If I replace the php code with a <h1>test</h1> the header gets displayed. When I add the PHP code nothing happens.

Is this maybe because of ROOT_PATH?


2 Answers

Finally got it to work!

    define("BASE_URL", "http://localhost:8888/shirts4mike/");
    define("ROOT_PATH", $_SERVER["DOCUMENT_ROOT"] . "/shirts4mike/");

// with


// and

include(ROOT_PATH . "inc/header.php"); 
Ken Haskins
Ken Haskins
299 Points

Thanks for sharing how you got this to work. I'd been trying to figure this out ALL DAY!

Sean T. Unwin
Sean T. Unwin
28,688 Points

ROOT_PATH should be defined. When using a development server with this project you could define it similar to:

// this will depend upon drive letter and directory structure
// Notice the escaped backward slash at the end of the string
define( 'ROOT_PATH', 'C:\mampp\htdocs\treehouse\php\shirts4mike\\');
// then you can use:
include( ROOT_PATH . 'inc/header.php' );

If doing this on a production server you can define ROOT_PATH as 'www.example.com'.

You could also use __DIR__. If you do you need to add a slash to the call directory:

include( __DIR__ . '/inc/header.php' );

Thank you for your suggestions Sean. I've tried both posibilities but failed. BASE_URL is set. Config file is loading. But the BASE_URL is not echoing.


<?php define ('BASE_URL', "http://localhost:8888/shirts4mike/');

$output = $output . '<img src="' . BASE_URL . $product["img"] . $product["name"] . '">';

// Returns


// Without the BASE_URL