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

Having issues with BASE_URL in products.php. Do you need to include the config file?

Just working through enhancing the simple php application stage, specifically cleaning up the web addresses. BASE_URL is not working in the products.php. Does it need an include in the products page?

Thanks, Dre

2 Answers

If you're BASE_URL constant is defined in your config file, than yes, you'll have to include that file at the top of your products.php page to make sure it works.

Maybe I'm missing it, but I can't seem to see it in Randy's code. Also since it's also in the includes folder do I just write the filename, without any slashes?

Do you have a link to the video so I can see if I can see it in Randy's file?

And whether it needs a slash to link to it depends on the file hierarchy and where the file you are link from is to the file you are linking too.

If products.php is in the same level directory as the includes folder, then no you wouldn't need any slashes.

Okay, I know why config.php is not linked to in the products.php file, and that's because instead it's linked to the shirts.php file.

Products.php file by itself doesn't really output anything. It just contains information, which we can assume here means that product.php will always be attached to another file.

In this case it's attached with shirt.php. Back up to 6:24 in that video. Randy is on shirt.php.

You'll see he first requires once the config.php file, than he requires the products.php file. The BASE_URL constant works in the product.php file because of this.

Image with the two require_once functions that the server basically copy and pasted the contents of each file where that require statement is, thus defining the BASE_URL from the config file so that it can be used in products.php or shirt.php.

Does that make sense?

Thanks, that makes sense now.