RE: [SMARTY] call to class/method -- function included
| From: | mark priatel | Date: | Sun, 15 Dec 2002 03:51:11 +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-6808@lists.php.net to get a copy of this message | ||
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]);
}
}
?>