Hi,
I have a problem with the structure of my website which is causing problem
with passing variables between functions, even when declared as global.
It would probably be easiest if I explain the structure in english instead
of listed loads of code:
page.php
include output.php
display header
display main
display footer
function content
output.php
function display header
function display main (table with menu on left and displays content from
main page on right)
function display footer
I have choosen this structure so the main layout for the site is all store
in function on a single page. The individual pages then contain a function
with their own content which is placed in the appropriate place by the
function in output.php
This works ok, the problem is with variables. If I declare a global variable
at the top of page.php, it will work fine within that page, but if I try to
call it within the content function, which is called through the output
file, then the variable is empty.
Has anyone got any better ideas for a structure which would solve the
variable problem?
Structure/Vairables Problem
Moderator: General Moderators
How are you declaring a global variable?If I declare a global variable at the top of page.php
You should really just need:
$var = 'foo';
include 'output.php';
(then in output.php)
function content(){
global $var;
//do whatever with $var
}
If i've misunderstood the exact layout then maybe some code snippets would help