The SitePoint Forums have moved.

You can now find them here.
This forum is now closed to new posts, but you can browse existing content.
You can find out more information about the move and how to open a new account (if necessary) here.
If you get stuck you can get support by emailing forums@sitepoint.com

If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

Best method to handle header/footer

Hey,

What would be the best method to handle header's and footer's?

I was thinking that doing a require_once for the header file, the actual content page and footer file per page. But I know that includes and requires are heavy. And then just doing something like example.php?ref=login to create dynamic sections. But then I started thinking every time I refferenced a new "example.php?ref=" I would also be calling the 3 required pages again. So I don't know if this would be a good way to go?

Or maybe do a class and initiate an object to return header / footer ?

What I originally had planned was to just have everything be html/css on each page and if I ever needed to change the header/footer I would just need to edit each individual one. I don't know if this would be the best method ? It parses less PHP so it makes it faster but it slows down on production because you have to edit each page one by one. But how often would I be editing the header and footers? Not very much is my guess.

Keep in mind that this site could generate millions per day. What I'm looking for mostly is performance and structure. How do some of these big dogs handle it?

Smarty is a terrible idea becasue it is highly inefficient. The concept can be replicated easily using pure php which basically comes down to my first example. Executing controllers from within the view makes the code highly reusable. The Masthead could access the state of the entire application easily if it could be executed in a nested fashion from within the view.

In my system I don't directly execute nested templates but indirectly through the execution of a sub module/controller.

The other thing to understand is that the template is a single object. However, you can class the fetch() method to execute a template file and return its contents.

PHP Code:

$objTemplate = new Template($this); // pass driver

$objTemplate->assign('title','title');

/* other assignments */

$content = $objTemplate->fetch('/templates/statics/home.php');

$objTemplate->assign('content',$content);

echo $objTemplate->fetch('/templates/layout/outside.php');

Its may be a little difficult to grasp so if you would just like to see some of the code behind all this just ask. However, the basic concept is that any template file can execute any module from within. This means that a site can essentially be broken up into pieces rather then pages and creates highly reusable blocks of code.

This is a simple example of how 9three's example could look in my system:

Its inspired by smarties fetch concept if you can't tell. Where there is a single template per request, it can be loaded with as much data as you would like and you can execute/fetch the content for as many template files as you would like.