Jump to content


Photo

functions on include


  • Please log in to reply
No replies to this topic

#1 onlyican

onlyican
  • Members
  • PipPipPip
  • Advanced Member
  • 921 posts
  • LocationHants - UK

Posted 21 September 2006 - 01:05 PM

Hey guys

No code here, just best practice

Lets explain how I set up a website

I create a file which is the header and include
This file contains the doctype, head, and anything in the body that aint the content (navigation ect)
and the div for the content

THen I have a footer file
On here, I have, well, my footer, and close all htm tags

Then on the main page I have something like
<?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");
?>


NOW
I make a lot of functions
Every form on my websites are in functions
This way I can do something like
<?php
if($_POST["fieldname"]){
if($_POST["CheckAllFieldsAreCompletedInAnIfStatement"]){

}else{
echo "Cant you complete a simple form<br />\n";
ShowForm();
}
}else{
ShowForm();
}
?>
(I dont have a field that long, each Cap letter is a new word, look closley)
WIth me so far

All this is so my question makes sence

The form functions, I create the function at the top of THAT page, as I am only going to call it on that page

BUT
I 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 pages

Soo

What is best practice to do these functions

If I call the function more than once, add it to the header include file, so tis there on all pages

OR

Create a new file for functions, function_includes.php or someting

OR

create a class, and call the functions via the class

OR

if i only call it 2 or 3 times, add it to the file thats calling it, if its more, add it to the header file

OR

err, well I cant think of any other way, so let me know what ya tink


The 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)
Tell me the problem, I will try tell you the solution




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users