|
Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon. |
|
View previous topic :: View next topic |
Author |
Message |
luke2000 Smarty Rookie
Joined: 29 Mar 2004 Posts: 13
|
Posted: Mon May 24, 2004 2:56 pm Post subject: smarty kills global variables? |
|
|
hi, i'm guessing that if you do a
smarty->display("index.tpl");
global variables are "lost"
cause i wrote a gallery (works fine with normal php)
now, i turn it into templated version
now stops working, (not the only one, also other scripts don't work anymore)
any way to change that? |
|
Back to top |
|
messju Administrator
Joined: 16 Apr 2003 Posts: 3336 Location: Oldenburg, Germany
|
Posted: Mon May 24, 2004 4:02 pm Post subject: |
|
|
no global variables are "lost".
they are just invisible inside functions and methods in php like the display() method of $smarty. |
|
Back to top |
|
luke2000 Smarty Rookie
Joined: 29 Mar 2004 Posts: 13
|
Posted: Mon May 24, 2004 4:03 pm Post subject: |
|
|
well.. have to find a workaround then
Luke |
|
Back to top |
|
hucky Smarty Rookie
Joined: 02 Sep 2004 Posts: 6
|
Posted: Tue Sep 07, 2004 8:56 pm Post subject: hei |
|
|
Quote: | hey are just invisible inside functions and methods in php like the display() method of $smarty.
|
??? can you give me an example how i can use this global variables?
and how invisible?
thx[/quote] |
|
Back to top |
|
boots Administrator
Joined: 16 Apr 2003 Posts: 5611 Location: Toronto, Canada
|
Posted: Tue Sep 07, 2004 11:06 pm Post subject: |
|
|
Sure, use either:
1) declare your intention to use a global var
global $var; // $var is now a reference to the global $var
$foo = $var;
or:
2) reference the superglobal (which is always in-scope):
$foo = $GLOBALS['var'];
More at the PHP manual:
http://php.net/language.variables.scope
http://php.net/reserved.variables
IMHO, globals suck. I usually get around it by having a static class that has functions that hold static vars to store data. With a little bit of thought you can can implement a class that organizes and unifies access to all of your shared data (static data, shared objects, singletons, etc) |
|
Back to top |
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|