Re: custom functions

From: Date: Thu, 21 Feb 2002 20:23:11 +0000
Subject: Re: custom functions
References: 1  Groups: php.smarty.general 
Request: Send a blank email to php-smarty-general+get-2823@lists.php.net to get a copy of this message
Luc Saint-Elie wrote: > > Heloo, > > I'm reading with interest this thread, and I have a remark and a question > > 1- remark > ========= > > The following is clear concrete and very easy to understand and might > perhaps be added to: > > http://www.phpinsider.com/php/code/Smarty/docs/x1215.htm#AEN2057 > > At 11:17 21/02/02 +0100, Ivo Jansch wrote: > >That's because of the way Smarty passes params to you. > > > >If your function is normally this: > > > >function func_getimage($path) > >{ > > // lalalalala... > >} > > > >then when using it in smarty, change it to this: > > > >function smarty_func_getimage($params) > >{ > > $path = $params["path"]; > > // lalalalalala > >} > > 2- Question > ========== > > What are the pro and cons of such a custom function versus a classical > function placed in the *.php file ? In Smarty 2.0 there is only one plugin directory, so for a custom function for your application you would probably want to put the function in your app and register it, just as you do now. There isn't much of a technical advantage of one over the other, it is just a matter of situation. So something like this: myapp_setup.php --------------- include("Smarty.class.php"); My_Smarty extends Smarty { $this->Smarty(); $this->register_function('myfunc','myapp_func_myfunc'); } function myapp_func_myfunc ( ... ) { ... }

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