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
We've moved the forum!
Please use forum.silverstripe.org for any new questions
(announcement).
The forum archive will stick around, but will be read only.
You can also use our Slack channel
or StackOverflow to ask for help.
Check out our community overview for more options to contribute.
- Page 11(current)
- 2
- Next 10 entries
Use your _config.php file.
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..
the problem is how recall ths global variable in my template
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;
}
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..
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 %>
Just out of interest, howcome you need to use a global variable?
- Page 11(current)
- 2
- Next 10 entries