Page 1 of 1

Passing vars to included files

Posted: Sat Mar 01, 2008 2:06 am
by chilling
I have a site with a number of shops all of which have their own mini web-site (currently only one index page!) which I want to include the same basic template and information but obviously put in the shops specific address etc.

I have created the following files:
/index.php
/address.php

/shop1/index.php
/shop1/address.php

/shop2/index.php
/shop2/address.php

/themes/theme1/header.php
/themes/theme1/body.php
/themes/theme1/footer.php

... a bit more complcated than that but you will understand my struture from the above.

The code for shop1/index.php file is:

Code: Select all

<?php
global $site_url, $site_shop;
 
$site_url='http://www.mysite.com';
$site_shop='shop1';
 
include $site_url.'/themes/theme1/header.php';
include $site_url.'/themes/theme1/page.php';
include $site_url.'/themes/theme1/footer.php';
?>
The above works - the header.php, page.php and footer.php display information as I am expecting but then I want page.php to add in the address details from each shop's address.php file which is where the problem occures:

Code for page.php is:

Code: Select all

... some HTML formatting
<?php
include $site_url . '/' . $site_shop . '/' $site_shop .'/address.php';
?>
... more HTML formatting
 
Code for address.php is:

Code: Select all

... just some HTML formatting
I can not get the page.php to include the shop's address as the $site_url and $site_shop variables are not being passed to page.php - what am i doing wrong?

Re: Passing vars to included files

Posted: Sat Mar 01, 2008 4:37 am
by Benjamin
Saw you on here so I figured I'd answer.

$site_url is available in page.php. So either it is incorrect, or you're trying to use it in a different memory space, ie function or class.

Re: Passing vars to included files

Posted: Sat Mar 01, 2008 5:28 am
by chilling
astions wrote:you're trying to use it in a different memory space, ie function or class.
How can I test that, because in both page.php and address.php there is no other php code appart from what I have shown everything else is html (ie there is no function or class in either page.php or address.php - only the 'include' in page.php)