1 00:00:00,000 --> 00:00:00,330 2 00:00:00,330 --> 00:00:02,230 >> DAVID MALAN: Now that our course's home page has gotten a bit more 3 00:00:02,230 --> 00:00:05,860 complex, it's probably time to start organizing related files into 4 00:00:05,860 --> 00:00:06,900 subdirectories. 5 00:00:06,900 --> 00:00:10,080 Allow me to propose this. 6 00:00:10,080 --> 00:00:14,520 For the course's home page, we can leave index.php, lectures.php, 7 00:00:14,520 --> 00:00:19,390 week0.php, and week1.php in the same directory as always. 8 00:00:19,390 --> 00:00:23,210 But let me propose that inside of a directory called includes, we put 9 00:00:23,210 --> 00:00:27,310 files that we might like to include, namely helpers.php. 10 00:00:27,310 --> 00:00:33,469 Meanwhile in templates, let me propose that we put footer.php and header.php. 11 00:00:33,469 --> 00:00:37,200 >> Now with those files and subdirectory, how do we require them 12 00:00:37,200 --> 00:00:38,530 in our actual code? 13 00:00:38,530 --> 00:00:43,570 Well, inside of index.php, notice that it suffices to now require not 14 00:00:43,570 --> 00:00:46,010 helpers.php alone but includes/helpers.php. 15 00:00:46,010 --> 00:00:48,720 16 00:00:48,720 --> 00:00:52,560 In other words, because the includes subdirectory is in the same directory 17 00:00:52,560 --> 00:00:57,260 that index.php is, it suffices simply to have this relative path of 18 00:00:57,260 --> 00:00:58,510 includes/helpers.php. 19 00:00:58,510 --> 00:01:00,900 20 00:01:00,900 --> 00:01:05,310 >> Meanwhile in helpers.php, notice that we have to get at the template a 21 00:01:05,310 --> 00:01:06,810 little bit differently. 22 00:01:06,810 --> 00:01:10,620 Inside of render, I'll still declare path, but I'll assign it a value of 23 00:01:10,620 --> 00:01:15,210 underscore underscore DIR underscore underscore, which is a special global 24 00:01:15,210 --> 00:01:21,280 constant that represents the directory inside of which helpers.php itself is. 25 00:01:21,280 --> 00:01:25,290 I'll then concatenate onto that using the dot operator the following-- 26 00:01:25,290 --> 00:01:31,255 slash dot dot slash templates slash and then concatenate further onto that 27 00:01:31,255 --> 00:01:34,490 the name of the temple followed by .php. 28 00:01:34,490 --> 00:01:39,610 >> In other words, if the template we're trying to get at is header.php, path 29 00:01:39,610 --> 00:01:44,300 will take on a value that's equal to the current directory that helpers.php 30 00:01:44,300 --> 00:01:48,915 is slash dot dot to go up one level in that tree, /templates/header.php. 31 00:01:48,915 --> 00:01:52,450 32 00:01:52,450 --> 00:01:56,420 In other words, in this way are all of our URLs effectively relative to 33 00:01:56,420 --> 00:01:59,060 wherever we might put these files on our hard drive. 34 00:01:59,060 --> 00:02:01,300 Nothing is hard coded absolutely. 35 00:02:01,300 --> 00:02:03,010 >> Now the rest of render is the same. 36 00:02:03,010 --> 00:02:05,320 I continue to check whether that path exists. 37 00:02:05,320 --> 00:02:08,720 I extract the keys into local variables, and I require 38 00:02:08,720 --> 00:02:10,330 the template itself. 39 00:02:10,330 --> 00:02:13,700 So all that I've done ultimately is reorganize my code, nothing that the 40 00:02:13,700 --> 00:02:15,040 user will actually see. 41 00:02:15,040 --> 00:02:16,290