Re: [SMARTY] Plugin problem
Jochem Maas <[email protected]> Sat, 04 Nov 2006 19:30:45 +0100
| Newsgroups | gmane.comp.php.smarty.general |
|---|---|
| Message-ID | <[email protected]> |
Erich C. Beyrent wrote:
> boots wrote:
>> Without knowing anything about your environment, my first thought on
>> this is to guess that you are probably using sessions and serializing
>> the Smarty object. If so, then don't. The Smarty object should never
>> be serialized because it contains environment specific state
>> information that may not be true once it is unserialized.
>>
>> xo boots
>>
>> *//*
> I am using sessions and storing the Smarty object in the session so that
> I can use it all over the site. I inherited a rat's nest of code, and
> was trying to prevent having to create new Smarty objects all over the
> place, but from what you are saying, that's what I am going to have to do?
// write a simple function (not sure if/where you need/want to use the references
// for the Smarty object var):
function &getSmart()
{
static $smarty;
if (!isset($smarty)) {
$smarty = new Smarty;
/* do some config */
}
return $smarty;
}
class someJunkyClassWrittenBySomeoneEvenLessCapableThanMe
{
function foo()
{
/* lots of rubbish code */
$s = getSmart();
$s->assign('foo', $foo);
return $s->fetch($templatefile);
}
}
// alternatively use a global variable reference.
function someJunkyRoutineWrittenBySomeoneEvenLessCapableThanMe()
{
global $myGlobalSmartyObject;
/* lots of rubbish code */
$myGlobalSmartyObject->assign('foo', $foo);
return $myGlobalSmartyObject->fetch($templatefile);
}
>
> -Erich-
>
--
Smarty General Mailing List (http://smarty.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php