Jump to content
MakeWebGames

Help With Header


gamble
 Share

Recommended Posts

I have decided to upgrade my game in ways making it neater and hopefully easier to use.

What I am wanting to know is how could i make a header.php that "does all the work" for example I post the following code

<?
require('header.php');
//content
print"Blah Blah Blah";
?>

 

That code also does footer. Basically what i am trying to do is something like Mccodes just 1 page for the whole template.

Can anyone help?

 

Thanks In Advance,

gamble

Link to comment
Share on other sites

<?php
class Template {
   public function __construct() {
       ob_start();
       return;
   }
   public function __destruct() {
       $content = ob_get_contents();
       ob_end_clean();
       ob_start();
       $this->getHeader();
       $this->getMenu();
       echo $content;
       $this->getFooter();
       ob_end_flush();
       return;
   }

   private function getHeader() {
       //Head things (doctype and such)
   }
   private function getMenu() {
       //Menu
   }
   private function getFooter() {
       //Footer things (closing body/html tags and such)
   }
}

$template = new Template();

<?php
require_once ('path/to/file');
echo 'Some content here';

Spudinski (well I think it was him :cool:), showed us this simple technique a while back, perhaps it may be of some use to you.

Edited by Djkanna
Link to comment
Share on other sites

Back on:

Topic.jpg

There are certainly multiple ways of doing this; a little time spent

researching front-end controllers will easily yield profitable results;

a few sites sadly do suggest the use of the switch() statement,

something that McCodes (Redux) incorporated imo mistakenly, a

sanitized controller name and file_exists() is often all that is

needed.

I'm pretty sure I've even seen a half decent example here, from

a while back; if not my mistake. Easy enough to rustle one up

though. Assuming the ability to access and write a .htaccess

file, the mod_rewrite extension will give you the ability to direct

every request through to a single dispatcher;

(Caveat) Static/Media files really should be served by something

like nginx or similar high speed front-end; you don't want every

little request for css, ico, gif, png, jpg, js etc going through there!

Link to comment
Share on other sites

We're supposed to be helping this fella out, not bitching at each other...

Page out of Octarine's book; Back ON ---

Topic.jpg

But before we do, darn it I now want a Topic, sheesh.

Edited by Djkanna
This freakin' reply box is killing me (slowly but surely) -.-
Link to comment
Share on other sites

Sod it, no one else is staying on topic.

Spelling;

It would take too long to list, but I would suggest using spell check before posting if you are going to attempt to call the kettle black, while dressed as a pot.

:)

EDIT:

You know, I may actually walk to the local 24 hour shop and grab one biggrin.png

Well you're just freakin' lucky, to live quite close to a 24 hour shop, unlike some of us. :(

EDIT 2:

I predict post deletion in 3.2.1... :P

Edited by Djkanna
Link to comment
Share on other sites

Jog? Run? Drive? You know it would be worth the walk, don't you? :D

Well it damn sure is tempting!

Back in a moment.

*Grabs coat*

EDIT:

Edit Too, in that context, is correct.

Darn it, I've had it wrong all these years, my bad.

Edited by Djkanna
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...