I have been trying to search a solution online and on stackoverflow but did not come across any satisfactory solution.
I wanted to know how can i include ( if required ) header.php
and footer.php
automatically in the new PHP pages that i create, at present whenever i create a new PHP file i manually add header.php
on top and footer.php
at the bottom, I dont really have a problem with doing this but i was wondering if this is how everyone does it and if not what is the best solution to this.
I know I could takeup any framework out there and use that because may be they include the header and footer automatically, but i am referring to custom PHP coding.
I will really appreciate views of experienced developers out there.
The usual approach is to use the front controller design pattern .
Use a single PHP file to load all the pages. Have it include the header and footer and use the URL (and whatever other information you like) to determine which content to include.
PHP developers often use mod_rewrite
to map URLs onto a single script. You could also use the Apache alias
directive.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.