patternphpMinor
Neatest way of including a header and footer on every page
Viewed 0 times
headerwayeveryneatestincludingfooterpageand
Problem
I just got into Object Oriented Programming, and it made me think about certain code how I can make them as efficient as possible.
Right now I am just including my header and footer like the following:
PHP
I wonder if this is the neatest / most efficient way of doing that?
Right now I am just including my header and footer like the following:
PHP
require_once 'core/init.php';
require_once 'includes/header.php';
//Big block of content goes here
require_once 'includes/footer.php';I wonder if this is the neatest / most efficient way of doing that?
Solution
If you are working in PHP use a framework that has MVC such as Laravel(up and coming and popular), Symphony, Yii, Codeigniter(defunct), etc.
Each of them will enable you to use some reuse mechanism.
Laravel itself uses a template PHP called blade. There are several other template mechanism such as Twig that enables you to template your views to even add more granular way and cleaner.
If its a single file system that you must what you are doing is fine because you are using require_once it enables you to call other files and you can modify that file and it will reflect any other files that references it.
Each of them will enable you to use some reuse mechanism.
Laravel itself uses a template PHP called blade. There are several other template mechanism such as Twig that enables you to template your views to even add more granular way and cleaner.
If its a single file system that you must what you are doing is fine because you are using require_once it enables you to call other files and you can modify that file and it will reflect any other files that references it.
Context
StackExchange Code Review Q#46059, answer score: 7
Revisions (0)
No revisions yet.