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 Building Websites with PHP Contact Form & Sending Email Named Routes

cynnimon
cynnimon
4,001 Points

How does "baseUrl()" know which page is the home page?

Hi, I'm confused how baseUrl() knew to serve the about.twig page. I thought it was the naming 'home' method, but after changing those around it had no effect. Does it just look through the Templates folder and pick the first file by alphabetical order?

2 Answers

consider this function.

function getPageName () { return basename($_SERVER['SCRIPT_FILENAME']); }

$page = getPageName();

echo $page;

it will always return the name of the current page u are on.

You need to check the source code of Slim Views to find this out. Having done that you will see that baseUrl() is mapped to the "/" route. ie

    $app->get("/", function() {});     //this is your baseUrl