Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

Archive

Our old forums are still available as a read-only archive.

Moderators: martimiz, Sean, biapar, Willr, Ingo, simon_w

where define my global variable?I have Error


Go to End
Reply

9 Posts   5595 Views

Avatar
bebabeba

2 December 2008 at 5:00am Community Member, 192 Posts

Hi!
I need define a global variable in my Page.php. I put global $a =0 after Page controller but is wrong..can you hel me to define my global varable?Where?Thanks

Avatar
Hamish

2 December 2008 at 10:14am Community Member, 712 Posts

Use your _config.php file.

Avatar
bebabeba

3 December 2008 at 9:01pm Community Member, 192 Posts

I use mysite/_config.php and I set:
global $a;
$a = 0;
then in my function I recall $a in this way:
global $a;
but seems not be a global variable..

Avatar
bebabeba

3 December 2008 at 9:10pm Community Member, 192 Posts

the problem is how recall ths global variable in my template

Avatar
Willr

4 December 2008 at 5:12pm Forum Moderator, 5511 Posts

If you want it in the template then you have to wrap it in a PHP function which returns the global.

So try this in your Page.php file

function SomeVar() {
global $_SOME_VAR;
return $_SOME_VAR;
}

Avatar
bebabeba

4 December 2008 at 9:42pm Community Member, 192 Posts

so in my config.php I can't declare nothing?
sorry but in my program I have may problem and i'm not sure the cause is global variable..

Avatar
bebabeba

4 December 2008 at 11:10pm Community Member, 192 Posts

ok..I understand what you say but my problem is that if my function return global variable (global value are 1 or 0) and call the function in template I see only 1 or 0 and all template disappear.
I need to use global value in template to print two different menu:
if global variable is equals to 1 print all menu otherwise if global variable is equals to 0 only 2 voices of menu.

so I recall function as:

<% if Somevar = 1 %>
....
<% else %>
..
<% end_if %>

Avatar
Sean

5 December 2008 at 12:10am Forum Moderator, 921 Posts

Just out of interest, howcome you need to use a global variable?

Go to Top