Re: [SMARTY] call to class/method -- function included

From: Date: Thu, 19 Dec 2002 11:11:33 +0000
Subject: Re: [SMARTY] call to class/method -- function included
References: 1  Groups: php.smarty.general 
Request: Send a blank email to php-smarty-general+get-6892@lists.php.net to get a copy of this message
Hi Mark! I think this is exactly what I want to do, thank you very much. I only have to copy this file into the "plugins" folder and I can use it as described? regards, Andreas
Hmm.. my attachment didn't seem to make it to the list.. Oh well, here's the source, for those interested. -mark <?php /* * Smarty plugin * -------------------------------------------------------------
* Type:     function
* Name:     call
* Author: Mark Priatel (mpriatel@rogers.com)
* Input:    obj = the object to call a method on
*           method = the method to call
*           arg1 .. arg4 (optional) = an argument for the method
* * Examples: {call obj=$connection method='close'}
*           {call obj=$connection method='open' arg1='localhost'}
*           {call obj=$connection method='open' arg1='localhost'
*                 arg2='password' }
* * ------------------------------------------------------------- */ function smarty_function_call($params, &$smarty) { $o = $params['obj']; if ( !isset($o) ){ $smarty->trigger_error("function 'call' requires argument 'obj'"); return; } $m = $params['method']; if ( !isset($m) ){ $smarty->trigger_error("function 'call' requires argument 'method'"); return; } $i = 1; $args = array(); while( isset($params["arg$i"]) ){ array_push($args,$params["arg$i"]); $i++; } switch( sizeof($args) ){ case 0: return $o->$m(); case 1: return $o->$m($args[0]); case 2: return $o->$m($args[0],$args[1]); case 3: return $o->$m($args[0],$args[1],$args[2]); case 4: return $o->$m($args[0],$args[1],$args[2],$args[3]); } } ?>


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