Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

Pass paramater through $smarty->register_function

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Feature Requests
View previous topic :: View next topic  
Author Message
diamonds
Smarty Rookie


Joined: 20 Sep 2005
Posts: 5

PostPosted: Tue Sep 20, 2005 10:10 pm    Post subject: Pass paramater through $smarty->register_function Reply with quote

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]
Code:
{func incr="2"}


Similar features are in PHP functions like
register_shutdown_function.
Back to top
View user's profile Send private message
boots
Administrator


Joined: 16 Apr 2003
Posts: 5611
Location: Toronto, Canada

PostPosted: Tue Sep 20, 2005 10:24 pm    Post subject: Reply with quote

Perhaps you would rather register_object?
Back to top
View user's profile Send private message
diamonds
Smarty Rookie


Joined: 20 Sep 2005
Posts: 5

PostPosted: Wed Sep 21, 2005 12:04 am    Post subject: Reply with quote

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
View user's profile Send private message
boots
Administrator


Joined: 16 Apr 2003
Posts: 5611
Location: Toronto, Canada

PostPosted: Wed Sep 21, 2005 12:43 am    Post subject: Reply with quote

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
View user's profile Send private message
diamonds
Smarty Rookie


Joined: 20 Sep 2005
Posts: 5

PostPosted: Thu Sep 22, 2005 12:21 pm    Post subject: Reply with quote

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
View user's profile Send private message
messju
Administrator


Joined: 16 Apr 2003
Posts: 3336
Location: Oldenburg, Germany

PostPosted: Thu Sep 22, 2005 1:21 pm    Post subject: Reply with quote

you can register an object's method es callback.
Back to top
View user's profile Send private message Send e-mail Visit poster's website
boots
Administrator


Joined: 16 Apr 2003
Posts: 5611
Location: Toronto, Canada

PostPosted: Thu Sep 22, 2005 6:21 pm    Post subject: Reply with quote

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
View user's profile Send private message
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Feature Requests All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP