Forum Moderators: coopster

Message Too Old, No Replies

Having trouble passing variables along to various elements of a page

variable not available to all files of a template system

         

russkern

2:01 pm on Oct 24, 2007 (gmt 0)

10+ Year Member



I developed a template system for a site I'm working on, based of the One-line Template engine discussion (awesome reference by the way).

The issue I'm having is that some of my page variables are not available to all the files I'm calling...

My page code is:

include ('./includes/vars.php');

// Register the Client ID passed through the URL
if((isset($_GET['sec_id'])) && (is_numeric($_GET['sec_id'])) ) {
$id=$_GET['sec_id'];
include_once ('./includes/mysql_connect.php');
$query = "SELECT sec_title, sec_description, sec_keywords, sec_content, sec_name FROM sections WHERE sec_id=$id";
$result = @mysql_query($query);
if (mysql_num_rows($result) == 1) {
$sec_row = mysql_fetch_array($result, MYSQL_NUM);
} else {
echo '<p>We are sorry, this section does not exist</p>';
}

} else {
echo '<h1> Page Error!</h1> <p> This page was accessed in error.</p>';
}

//---This is where we set all our values - The "vars.php" file sets the domain path and it is pre-pended
//---to the files called so that we can display dynamic content at will. Setting the doamin path in the
//---var file also allows us to change the path by only modifying one file when we move the site live.
$page_name = $sec_row[4];
$title = $sec_row[0];
$description = $sec_row[1];
$keywords = $sec_row[2];

$header=file_get_contents($domain_path."includes/header1.html");

$nav=file_get_contents($domain_path."includes/nav.php");
$pgs_nav=file_get_contents($domain_path."includes/pgs_nav.php");

$content= $sec_row[3];

$footer=file_get_contents($domain_path."includes/footer1.html");
$rt ="";
// ------ END Set Page contents ------//
// ------ START page template call -------//
include ('templates/home_template.php');
// ------ END page template call -------//

This page works correctly all except for one thing...

the $pgs_nav... line around line 32 requires that the $id variable in or around line 6 be passed to that file so that the script draws the correct entries from the database for that section...

I know the script works because I get my "no info available" message that I should get if there is not a match...

Does anyone have any ideas why it does not seem to recognize the variable?

I hope I have explained myself well enough... I would appreciate any help...

Russ

vincevincevince

7:01 am on Oct 26, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Be careful to ensure that in $nav=file_get_contents($domain_path."includes/nav.php"); '$domain_path' is a server path, not an http path, e.g. /var/www/example.com/ not http://example.com/

If you are expecting read $id from within a function {} then you need to use: global $id; before trying to read it.