View previous topic :: View next topic |
Author |
Message |
diamonds Smarty Rookie
Joined: 20 Sep 2005 Posts: 5
|
Posted: Tue Sep 20, 2005 10:10 pm Post subject: Pass paramater through $smarty->register_function |
|
|
I would like it if $smarty->register_function should be able to pass a paramater, ideally for passing by refrence.
[php:1:65376ca497]function func($attrs,&$obj){
if(isset($attrs['incr'])){
$obj->i += $attrs['incr'];
}
}
$object = new whatever;
$smarty = new Smarty;
$smarty->register_function('func','func', /*...*/ , $object);
$smarty->display('main.tpl');[/php:1:65376ca497]
Similar features are in PHP functions like
register_shutdown_function. |
|
Back to top |
|
boots Administrator
Joined: 16 Apr 2003 Posts: 5611 Location: Toronto, Canada
|
Posted: Tue Sep 20, 2005 10:24 pm Post subject: |
|
|
Perhaps you would rather register_object? |
|
Back to top |
|
diamonds Smarty Rookie
Joined: 20 Sep 2005 Posts: 5
|
Posted: Wed Sep 21, 2005 12:04 am Post subject: |
|
|
Somthing like this would do, but it dosen't seem like the most efficent solution. There ARE other reasons, though, that passing additional arguments would be needed that would NOT work with register_object, like passing strings. For example, force a limited set of arguments on the programming end.
[php:1:5e9738634f]
function func($attrs,$banned_attrs){
//code
}
$smarty->register_function('func','func',...,array('hi'));
[/php:1:5e9738634f] |
|
Back to top |
|
boots Administrator
Joined: 16 Apr 2003 Posts: 5611 Location: Toronto, Canada
|
Posted: Wed Sep 21, 2005 12:43 am Post subject: |
|
|
Perhaps I am not understanding the entirety of your need. I am referring to the behaviour documented here: http://smarty.php.net/manual/en/advanced.features.php#advanced.features.objects
This does allow for you to whitelist methods to be called and it assumes that you setup your object appropriately before registering it, which seems essentially the same as what you want. The main difference being that instead of passing to functions you pass to methods inside of objects that are already initialized. |
|
Back to top |
|
diamonds Smarty Rookie
Joined: 20 Sep 2005 Posts: 5
|
Posted: Thu Sep 22, 2005 12:21 pm Post subject: |
|
|
There are other reasons you would want to pass a string/number/whatever to a function as a paramater, from thr programing end. But it is somthing that I would like to see. (This IS the Feature Requests forum, right?)
[+Edit]
I have found a reason. If you want to use, say, the
you must print the code like this:
{dhtml_calendar_init src='/path/to/calendar.js' setup_src='/path/to/calendar-setup.js' lang='/path/to/lang/calendar-en.js' css='/path/to/calendar-theme.css'}
This could all be removed by having the programmer say where the paths are. This could be reduced to {dhtml_calendar_init} this way. You COULD use {dhtml_calendar_init src=$dhtml.src setup_src=$dhtml.setup lang=$dhtml.lang css=$dhtml.css}, but that is just horribly iniffecient. |
|
Back to top |
|
messju Administrator
Joined: 16 Apr 2003 Posts: 3336 Location: Oldenburg, Germany
|
Posted: Thu Sep 22, 2005 1:21 pm Post subject: |
|
|
you can register an object's method es callback. |
|
Back to top |
|
boots Administrator
Joined: 16 Apr 2003 Posts: 5611 Location: Toronto, Canada
|
Posted: Thu Sep 22, 2005 6:21 pm Post subject: |
|
|
diamonds wrote: | This could all be removed by having the programmer say where the paths are. This could be reduced to {dhtml_calendar_init} this way. You COULD use {dhtml_calendar_init src=$dhtml.src setup_src=$dhtml.setup lang=$dhtml.lang css=$dhtml.css}, but that is just horribly iniffecient. |
I find this debatable since you can always setup an object first and have your plugin get features through that object. I have an interesting and perhaps more more powerful plugin metaphor in the works. Check out the SmartyDoc addon in the addons forum and look at the plugin api. It has actually evolved somewhat since my last post there but it should give you an idea of the direction I am heading with that. |
|
Back to top |
|
|