I split up my website using code refactoring with templates.
When I go to construct a basic link in my nav.php file or I suppose anywhere on the site for that mater, I need to grab multiple files as the site is templated — let’s assume for this example the user is going to services.php.
I believe I would need to attach all of these files in the link:
- header.php
- nav.php
- pages/services.php
- footer.php
How do I go about constructing a link to accomplish this? Could I make some sort of array and attach all of the files in the link and then loop through the array with a foreach statement and echo the results?
You don’t grab the other files through the link. You link to one URL, which processes a single PHP file and that PHP file includes all of the other necessary files. For example, your link might be:
Which will run services.php, which will then include the header, nav, footer, etc. For example services.php could look like this:
Using something like Smarty would be a nice and clean way of implemtning views in a MVC setup.