PHP function() {

Having problems with DHTML Menu? There is usually somebody here who knows the answer.
Post Reply
slackbladder
Super Advanced
Super Advanced
Posts: 72
Joined: Fri Jul 01, 2005 3:04 pm

PHP function() {

Post by slackbladder »

Hi,

Is it possible to use the menu with PHP function name() { to call the menu files (js)? I am using the PHP_MYSQL solution.

EXAMPLE:

INDEX.PHP

Code: Select all

<?php

function home(){
include('header.php');
echo "<table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n";
echo "<tr><td valign=\"top\">\n";
PAGE CONTENT
echo "</td></tr>\n";
echo "</table>\n"; 
}

switch ($name) {

default:
    home();
    break;      
}
?>


HEADER.PHP

Code: Select all

<?php
echo "<head>etc\n";
echo "<body>etc\n";

include("mm_config.php");  // This file contains all of the user editable parameters
include("mm_phpmenu.php"); // This is the file containing all of the PHP functions
buildMySQLMenu(1); // This line builds the menu from MySQL data tables.


?>
It works fine having the index.php file call another PHP file header.php containing the menu calls but if you use functions (function name() { ) in the index.php to call header.php it doesn't work.

Bugger!! does anyone understand what I mean and can you help?

Thx
slackbladder
Super Advanced
Super Advanced
Posts: 72
Joined: Fri Jul 01, 2005 3:04 pm

Post by slackbladder »

Typical!! :?

Takes me 1/2 an hour to try to explain the problem - then I solve it myself straight after!!! :x :D

If anyone else is having the same problem, adding:

Code: Select all

global $menuVars;
at the top of your 'function' fixes it (well did for me anyway) :D
User avatar
Andy
Milonic
Milonic
Posts: 3308
Joined: Sun May 19, 2002 8:23 pm
Location: Menu Developer
Contact:

Post by Andy »

That gets a lot of people, variables, in PHP, are not global by default and need to be declared as global inside functions.

Thanks for posting the fix.

Cheers,
Andy
Post Reply