I've got a menu system that uses php to determine which section of my site is currently being viewed, so that the correct menu can be shown. This system has worked fine while the code has been stored in files on my server, but now I am trying to move it into the CMS I am using (ExpressionEngine) and I am running into problems. The code in question can be viewed within these files:
http://www.hippoiathanatoi.com/Files/Menu-Array.txt (this code determines the 'Menu' variable)
http://www.hippoiathanatoi.com/Files/Menu-Main.txt (this is one of the menues using the 'Menu' variable)
http://www.hippoiathanatoi.com/Files/Menu-OnLoad.txt (this code passes the 'Menu' variable to the javascript)
http://www.hippoiathanatoi.com/Files/Menu-Sub.txt (this is one of the menues using the 'Menu' variable)
A member of the support team for ExpressionEngine suggested that this is because the templates (which do allow php within them) use eval() to process php, and that this results in the variables not being available globally. More specifically, he quoted this from their knowledge blog:
PHP used within a template is processed by the PHP function eval(). Because of this, variables in your PHP code are all considered to be of local scope, and your functions will not be able to reference them unless they are explicitly declared as globals.
He did, however, think that the code could be reworked to take this account ... but I am afraid that I have good idea how. I did try simply placing 'global' in front of the $Menu variable, as the example seemed to suggest could be done, but that didn't do the trick. However, I had a lot of help putting this code together in the first place, and my knowledge of php is quite limited. So, if anyone could help me out I'd really appreciate it. 🙂