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   5684 Views

Avatar
bebabeba

Community Member, 193 Posts

2 December 2008 at 5:00am

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

Community Member, 712 Posts

2 December 2008 at 10:14am

Use your _config.php file.

Avatar
bebabeba

Community Member, 193 Posts

3 December 2008 at 9:01pm

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

Community Member, 193 Posts

3 December 2008 at 9:10pm

the problem is how recall ths global variable in my template

Avatar
Willr

Forum Moderator, 5513 Posts

4 December 2008 at 5:12pm

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

Community Member, 193 Posts

4 December 2008 at 9:42pm

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

Community Member, 193 Posts

4 December 2008 at 11:10pm

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

Forum Moderator, 922 Posts

5 December 2008 at 12:10am

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

Go to Top