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

Alexis Leblanc-Isabelle
Alexis Leblanc-Isabelle
9,558 Points

Logic problem

I don't understand the logic behind this video. We change the way we include the header.php to use the root path. So we have to require the config.php before all the header include. And then inside the header.php, we use a constant set inside a config.php to change all the links. So now, we always need the config.php to be included for the header.php to work. So what about shirt.php, shirts.php and other. We have to go through all those files to include the config.php for the constant to work ? I'm not sure to understand. Isn't there a place where we could require the config.php only once so all our files can acces the constant inside the config ? I thought to require the config inside the header so all the files will have access to it but we need the config to call the header os it cannot be inside it.

Thanks for the help !

1 Answer

Hello!

Yes, the changes you described would be necessary to access the constant throughout the application. It's not so bad.. because once you've done it once, any changes you make will be to the config.php file instead of 10 different files.

Further down the road, you'll probably find that most modern application design will take all urls through one page:

www.mywebsite.com/home

www.mywebsite.com/about

www.mywebsite.com/product/123

will all be routed through index.php. You'll initiate everything within index.php, and then the app will decide how to respond after that. This is different to the shirts4mike setup, where you'll call one page per url e.g. www.mywebsite.com/about will go to /about.php. Because about.php has been called independently to the rest of the application, you'll need to set up everything you need in that file.

So yes! What you've said is bang on and exactly what you're going to be using in the near future. You'll be interested in the Laravel courses after this I imagine ;)

Alexis Leblanc-Isabelle
Alexis Leblanc-Isabelle
9,558 Points

Thanks for the reply ! And I'll probably be looking at Laravel but I wasn't sure between Laraval and Cakephp. Unfortunately, teamtreehouse doesn't have a Cakephp course.

  • Cheers !