Re: [SMARTY] Plugin problem

From: Date: Sat, 04 Nov 2006 18:30:45 +0000
Subject: Re: [SMARTY] Plugin problem
References: 1 2  Groups: php.smarty.general 
Request: Send a blank email to php-smarty-general+get-13555@lists.php.net to get a copy of this message
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- >

« previous php.smarty.general (#13555) next »