In short I am looking for best practices for managing document root references.
I've been trying to work through this problem for about three weeks and can't seem to get it right. I am having difficulty with the root file structures of items as I work across different computers (depending on who in the house is working, etc.) and once the site is migrated to the live host (that has a different root path entirely). Is it possible to create a single line of code that defines the root file structure globally throughout the project? That way when I start working at a new computer or upload the project I don't have to go through every line referencing a file and alter the code, but instead change a single line of code? Maybe I'm wrong, but it seems silly to me that this would not be an extremely simple thing to do.
I have tired the
<base>
tag; however, it a appears that this only works for html code. Also I have found that it hasn't worked in every case. Not sure if this is user error or what.
The other complication is I recently started using a php include tag for the header, footer, and navigation across pages. I also filed pages that are not the index.php in a pages folder.
I have used this php code (thanks youtube), but It doesn't work across pages (I can't reference $path if I am on a page without the rest of the code). So I still have the same problem of having to change the code across multiple pages, etc. before I can start working at a different computer and the
<base>
tag doesn't work here, because again it only works with html code.
<?php
$path = $_SERVER['DOCUMENT_ROOT'];
$path .= "/root/assets/header.php";
include_once($path);
?>
Other notables
My file structure is build like this:
root/
• css
• Images
• Assets
• pages
• Etc.
Host: Namecheap / Cpanel
Xampp 3.2.4
Brackets Release 1.14
Github
So what am I missing or is this just a cumbersome thing everyone deals with?