>> DAVID MALAN: Now that our course's home page has gotten a bit more
complex, it's probably time to start organizing related files into
subdirectories.
Allow me to propose this.
For the course's home page, we can leave index.php, lectures.php,
week0.php, and week1.php in the same directory as always.
But let me propose that inside of a directory called includes, we put
files that we might like to include, namely helpers.php.
Meanwhile in templates, let me propose that we put footer.php and header.php.
>> Now with those files and subdirectory, how do we require them
in our actual code?
Well, inside of index.php, notice that it suffices to now require not
helpers.php alone but includes/helpers.php.
In other words, because the includes subdirectory is in the same directory
that index.php is, it suffices simply to have this relative path of
includes/helpers.php.
>> Meanwhile in helpers.php, notice that we have to get at the template a
little bit differently.
Inside of render, I'll still declare path, but I'll assign it a value of
underscore underscore DIR underscore underscore, which is a special global
constant that represents the directory inside of which helpers.php itself is.
I'll then concatenate onto that using the dot operator the following--
slash dot dot slash templates slash and then concatenate further onto that
the name of the temple followed by .php.
>> In other words, if the template we're trying to get at is header.php, path
will take on a value that's equal to the current directory that helpers.php
is slash dot dot to go up one level in that tree, /templates/header.php.
In other words, in this way are all of our URLs effectively relative to
wherever we might put these files on our hard drive.
Nothing is hard coded absolutely.
>> Now the rest of render is the same.
I continue to check whether that path exists.
I extract the keys into local variables, and I require
the template itself.
So all that I've done ultimately is reorganize my code, nothing that the
user will actually see.