Re: [SMARTY] call to class/method -- function included
| From: | M Mohr | Date: | Thu, 19 Dec 2002 12:41:41 +0000 |
| Subject: | Re: [SMARTY] call to class/method -- function included | ||
| References: | 1 2 | Groups: | php.smarty.general |
| Request: | Send a blank email to php-smarty-general+get-6894@lists.php.net to get a copy of this message | ||
On Thu, Dec 19, 2002 at 12:11:33PM +0100, akorthaus@web.de wrote:
> 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]);
what about "call_user_method_array($m, $o, $args);" ?
it is available since 4.0.5 (so widely supported) and handles an arbitrary
number of args.
have fun
messju
> > }
> >
> >}
> >?>
> >
> >
> >
> >
> >
>
>
>
>
>
>
> --
> Smarty General Mailing List (http://smarty.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php