gamble Posted January 30, 2012 Share Posted January 30, 2012 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 Quote Link to comment Share on other sites More sharing options...
Djkanna Posted January 30, 2012 Share Posted January 30, 2012 (edited) <?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 January 30, 2012 by Djkanna Quote Link to comment Share on other sites More sharing options...
Octarine Posted January 30, 2012 Share Posted January 30, 2012 Back on: 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! Quote Link to comment Share on other sites More sharing options...
Djkanna Posted January 30, 2012 Share Posted January 30, 2012 (edited) We're supposed to be helping this fella out, not bitching at each other... Page out of Octarine's book; Back ON --- But before we do, darn it I now want a Topic, sheesh. Edited January 30, 2012 by Djkanna This freakin' reply box is killing me (slowly but surely) -.- Quote Link to comment Share on other sites More sharing options...
Djkanna Posted January 30, 2012 Share Posted January 30, 2012 (edited) 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 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 January 30, 2012 by Djkanna Quote Link to comment Share on other sites More sharing options...
Djkanna Posted January 30, 2012 Share Posted January 30, 2012 (edited) 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 January 30, 2012 by Djkanna Quote Link to comment Share on other sites More sharing options...
Octarine Posted January 30, 2012 Share Posted January 30, 2012 Bugger it... Somebody get me a and a Quote Link to comment Share on other sites More sharing options...
Djkanna Posted January 30, 2012 Share Posted January 30, 2012 (edited) @SRB: Excellent idea! @Oct: Urm, get me a coffee whilst you're out getting those things. @Cav: Stop. @SRB2: On par, with your first idea pal. Edited January 30, 2012 by Djkanna Punctuation slip = NEED MOAR COFFEE! Quote Link to comment Share on other sites More sharing options...
Nickson Posted January 30, 2012 Share Posted January 30, 2012 Off topic: Yes Locked: Yes Funny: a little bit.. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.