I am programming with Php and i need these elements constant through the web page:
header, sidebar & footer (all php files)
all these files define the respective functions like create_header() and so on that generate the html and i have a css that layout these elements (using div id="header",id="sidebar"..)
as for the pages of actual content all they do is include this files, make the calls and then generate their respective content, all layout through divs, all their content is inside the div class="content"
is it good practice to use this for each page or which method should i use?
This is the system that I use when programming with PHP, and it works well for me. It's a good way to ensure consistency, provided that you remember to add the includes to all pages. It also makes updating the layout of the website easier. It's a shame there is no Template or Master Page in PHP, which would be more robust. However, I would strongly recommend HTML's new semantic tags, including
<header>
,<footer>
and<sidebar>
instead of giving id's to appropriate<div>
's.This is what I use for my applications. See if this helps:
site_config.php:
This is what my template looks like:
site_header_begin.php:
site_header_end.php:
site_footer.php:
This will make header/footer "constant" and dynamic and everything will be defined in terms of constants defined in the site_config.php file. You just need to add appropriate views, static, classes and components directories. See if this helps.
include
function in PHP is a good way to make the website template constant header and left pane.in1.php (this file contains top part of the constant interface)
Then the foot(bottom) part
in2.php (this file contains the constant end part of the web site)
Finally we can define the dynamic parts of the web site. I have demonstrated a login window.
login.php