onlyican Posted September 21, 2006 Share Posted September 21, 2006 Hey guysNo code here, just best practiceLets explain how I set up a websiteI create a file which is the header and includeThis file contains the doctype, head, and anything in the body that aint the content (navigation ect)and the div for the contentTHen I have a footer fileOn here, I have, well, my footer, and close all htm tagsThen on the main page I have something like[code]<?php$page_title = "My Page";require("inc/myheadefile.php");echo "Hello and welcome, this is the content, all ready to go";require("inc/myfooterfile.php");?>[/code]NOWI make a lot of functionsEvery form on my websites are in functionsThis way I can do something like[code]<?phpif($_POST["fieldname"]){if($_POST["CheckAllFieldsAreCompletedInAnIfStatement"]){}else{echo "Cant you complete a simple form<br />\n";ShowForm();}}else{ShowForm();}?>[/code](I dont have a field that long, each Cap letter is a new word, look closley)WIth me so farAll this is so my question makes senceThe form functions, I create the function at the top of THAT page, as I am only going to call it on that pageBUTI have functions, they I may call on every page (I have a function to connect to the DB, which is on most pages)and I have functions, which I may call on 3 out of 20 pagesSooWhat is best practice to do these functionsIf I call the function more than once, add it to the header include file, so tis there on all pagesORCreate a new file for functions, function_includes.php or sometingORcreate a class, and call the functions via the classORif i only call it 2 or 3 times, add it to the file thats calling it, if its more, add it to the header fileORerr, well I cant think of any other way, so let me know what ya tinkThe reason for this is, if I have too many functions on the header, then that is being called on EVERY page, and wont it be a stress for PHP to read "Waste Code" as I wont be usning that function on that page(As you may have clicked, I am a lil crazy, but thats why ya love me) 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.