Re: [SMARTY] Assign a reference to a variable

From: Date: Fri, 02 Aug 2002 09:01:08 +0000
Subject: Re: [SMARTY] Assign a reference to a variable
References: 1  Groups: php.smarty.general 
Request: Send a blank email to php-smarty-general+get-5549@lists.php.net to get a copy of this message
I sent up a patch a week ago to add an assign_by_ref function to smarty....never got any response. Heres the function though if you want to modify your Smarty.class.php /*======================================================================*\ Function: assign_by_ref() Purpose: assigns values to template variables using references \*======================================================================*/ function assign_by_ref($tpl_var, &$value) { if ($tpl_var != '' && isset($value)) $this->_tpl_vars[$tpl_var] = &$value; $this->_extract = true; } You cant do it with the assign function as it is right now. And they would lose backwards compatibility to modify assign to work with references. We use this effectively for just about every $var we assign to smarty. Bob Silva Senior Developer Bravenet.com ----- Original Message ----- From: "Rasmus T. Mohr" <rmo@netpointers.com> To: "'Hendy Irawan'" <ceefour@gauldong.net>; <smarty-general@lists.php.net> Sent: Friday, August 02, 2002 12:23 AM Subject: RE: [SMARTY] Assign a reference to a variable > Is it a problem? In the first example you are passing a copy of $myobj to > the templates and then modifying the attributes of the original object (not > the one passed to the templates). In the second example you are passing by > reference, so further changes will affect the object known to the templates. > > This is intended behavior... > > ----------------------------------------------------------- > Rasmus T. Mohr Phone : +45 70 117 117 > Application Developer Direct : +45 36 910 122 > Netpointers Intl. Mobile : +45 28 731 827 > Vestergade 18 B Website : www.netpointers.com > 1456 Copenhagen K Email : rmo@netpointers.com > > > > -----Original Message----- > > From: Hendy Irawan [mailto:ceefour@gauldong.net] > > Sent: Friday, August 02, 2002 8:40 AM > > To: smarty-general@lists.php.net > > Subject: [SMARTY] Assign a reference to a variable > > > > > > smarty-general, > > > > I want to do something like: > > > > $smarty->assign('myobj', $myobj); > > > > Where $myobj is an object. However, later I want to change $myobj > > (before displaying the template) but the changes are not visible. > > > > Doing: > > > > $smarty->assign('myobj', &$myobj); > > > > seems to have no effect. > > > > Is there a way to solve this problem? > > Assigning these variables exactly before it's displayed is not a > > solution. > > > > Salam hangat, > > Hendy Irawan - www.GaulDong.NET > > Kantor: (021) 5260467 [SoftVation] > > Kos: (021) 5261839 [kamar 3] > > > > > > -- > > Smarty General Mailing List (http://smarty.php.net/) > > To unsubscribe, visit: http://www.php.net/unsub.php > > > > > > > -- > Smarty General Mailing List (http://smarty.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php >

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