|
Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon. |
|
View previous topic :: View next topic |
Author |
Message |
corteccio Smarty Rookie
Joined: 16 Jan 2010 Posts: 5
|
Posted: Sat Jan 16, 2010 2:25 am Post subject: Passing $smarty.request.* to registered object method |
|
|
Hi,
new to smarty and not sure I am getting it right. I'm using 3.0b6.
A class:
Code: |
class Object {
function method($string) {
return md5($string);
}
}
|
Register the object:
Code: |
$smarty->register_object('obj', $object, NULL, FALSE, NULL);
|
Try to pass it a POST variable:
Code: |
{obj->method p1=$smarty.request.var}
|
When processing I get this from PHP:
Code: |
PHP Warning: md5() expects parameter 1 to be string, object given
|
So it seems what is passed back to my method is a Smarty object and not the value of the POST variable.
Is this normal? How do I pas the value?
thanks
Luca |
|
Back to top |
|
U.Tews Administrator
Joined: 22 Nov 2006 Posts: 5068 Location: Hamburg / Germany
|
Posted: Sat Jan 16, 2010 12:12 pm Post subject: |
|
|
There was a bug in the handling of the format parameter of the register_object method.
This is fixed in the SVN now.
Note that instead of using register_object you can also assign objects as Smarty variable.
Code: | $smarty->assign('obj',$object); |
Template
Code: | {$obj->method($smarty.request.var)} |
|
|
Back to top |
|
corteccio Smarty Rookie
Joined: 16 Jan 2010 Posts: 5
|
Posted: Sat Jan 16, 2010 4:05 pm Post subject: |
|
|
Oh, good, I'll retest soon.
By the way, is there any advantage in assign_by_ref over assign? I guess assign_by_ref avoids copying the object over.
Also by assigning the object instead of registering it I think the ability to restrict methods accessible from the templates is lost.
thanks
Luca |
|
Back to top |
|
U.Tews Administrator
Joined: 22 Nov 2006 Posts: 5068 Location: Hamburg / Germany
|
Posted: Sat Jan 16, 2010 4:09 pm Post subject: |
|
|
There is no advantage of assign_by_ref for objects as in PHP5 objects are always handled as reference.
You are right, if you assign objects you can't restrict the access to methods. |
|
Back to top |
|
corteccio Smarty Rookie
Joined: 16 Jan 2010 Posts: 5
|
Posted: Mon Jan 18, 2010 4:41 pm Post subject: |
|
|
U.Tews wrote: | There is no advantage of assign_by_ref for objects as in PHP5 objects are always handled as reference.
|
Great to know.
Quote: |
You are right, if you assign objects you can't restrict the access to methods. |
I guess, not even by prefixing methods with _ since this is just a reference.
I like the cleaner syntax of assigned objects, and maybe from a security pov is also better to know any method in an assigned class is accessible to the templates, so just don't put it there. |
|
Back to top |
|
|
|
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
|