Re: smarty-general Digest 25 Feb 2003 09:52:10 -0000 Issue 198

From: Date: Tue, 25 Feb 2003 14:52:40 +0000
Subject: Re: smarty-general Digest 25 Feb 2003 09:52:10 -0000 Issue 198
References: 1  Groups: php.smarty.general 
Request: Send a blank email to php-smarty-general+get-8185@lists.php.net to get a copy of this message
At 04:52 AM 2/25/03, gerard@interfold.com wrote:
From: "Gerard" <gerard@interfold.com> To: "Smarty-General" <smarty-general@lists.php.net> Date: Tue, 25 Feb 2003 01:48:13 -0700 Message-ID: <ILEPLGCLIJOCNINEJCJPIEOADLAA.gerard@interfold.com> MIME-Version: 1.0 Content-Type: text/plain;
        charset="iso-8859-1"
Content-Transfer-Encoding: 7bit Subject: register_function with object method? Is it possible to register an object method for the impl in register_function? Gerard
I recently wished I could do that too. Here is what I wound up doing: I sub-classed Smarty and added my method to it. Then I wrote a wrapper function to call the method, taking advantage of the fact that &$smarty is passed to registered functions. Here is a pseudo-code example: class my_class1 extends smarty { function my_method( $params ) {
      # do certain stuff
      return $something;
} } class my_class2 extends smarty { function my_method( $params ) {
      # do different stuff
      return $something;
} } function my_function( $params, &$smarty ){ return $smarty->my_method( $params ); } I did this for a site that was written with code cleanly separated into Model, View, and Controller objects. There are two different View objects to provide two different looks to the site, but only one Control object, which drives both looks. In preparation for adding a third look, I am replacing my View objects with sub-classed Smarty. For a site with only one look, I would probably just move my methods out into functions, but this was the best approach I could determine. Any comments would be welcome. For the curious, here are the two sites: http://www.bernat.com/ http://www.sugarncream.com/ To date, only the home pages have been converted to Smarty. -- Mike van Lammeren Web Application Developer Emerge2 Digital Inc., "evolving business to digital" Web: http://www.emerge2.com Email: mike@emerge2.com

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