Hi there
I'm using Evolution on a nice site that's been live for a year or two. I'm adding a snippet for some custom PHP code. I need to access a variable that's outside of a function within the snippet. On a standalone page, I'd use the global keyword. That doesn't seem to work within the snippet.
For example, is there a way to do the equivalent to this?:
<?php
$a = 1;
function Sum()
{
global $a;
/(/$a would be 1)
}
?>
Thanks hugely in advance.
This must have been asked a hundred times.
I have to say, MODX is excellent - both Evolution and Revolution. I recommend it to everyone and wouldn't use anything else.
This new website, and especially the forum design, is awful! I know that's not the best way to get help! - a criticism. I need to defend why I can't find an answer. I have tried to search. I'd not logged in since the change - and this design is so bad, the forums literally aren't usable for their proper purpose.
I hope there are plans to redesign this site or to revert to something that works. It's an awful shame, and such a waste of so much valuable info.
-
☆ A M B ☆
- 24,524 Posts
PHP in MODX snippets and plugins is regular PHP, so what you're doing should work.
That said, I've run into situations where the global variable was not recognized inside the function. I never figured out why, but the solution is to pass the variable to the function as an argument.
-
☆ A M B ☆
- 24,524 Posts
Keep in mind that in Evo, snippets are run via the PHP eval() function, so some things are not quite as might be expected.