I am building a website and would like to ask something about best practices when having pages in different folders.
In my case, I would like to have a page in ../store/ and I have called it index.php.
This page loads external content, for example, the Header which is stored in the parent directory ../ along with some other pages. These pages loaded are used by other pages located in other subfolders.
The question is : Is it a better practice to have the Header (for example) replicated in each of the subfolders where an page is stored and will be using it?
Meaning I would call the header as header.php. Or is it better to have just 1 header in the parent and call it every time as ../header.php ?
———— UPDATE
In my site, I have an index.php in the parent directory. This index.php has a include that calls adds commonItems/header.php. At the same time, this header.php has a <?php include("commonItems/menu.php"); ?> to add the menu.
Then there is a folder in the parent that is called store/ in which I have another index.php which also adds ../commonItems/header.php. However, in this case, the header is added properly but the menu.php does not show up….
Any idea of how to solve this?
There is no point in having multiple
phppages with the same content in different folders, especially if you are going to use them across the website.In case of changes/maintainability, you’ll have to make changes across all the folders where these files are located, which would make it very difficult to maintain.
So, if you use a file across various pages, might as well, put it in one place and call it from across the website.
To call them, I usually prefer to define a constant and use that, so :