|
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 |
CirTap Smarty Pro
Joined: 04 Jun 2003 Posts: 106
|
Posted: Thu Aug 07, 2003 8:09 pm Post subject: Need some info on register_object() |
|
|
Hi,
I have some questions considering register_object():
1.) can someone explain to me what "the traditional object parameter format" is supposed to be? Except for the boolean, I can find no difference in the function call and there's no example given to illustrate the difference in the template.
2.) how do I prevent Smarty from throwing an error and stop execution if I give a list of allowed methods/properties as the third parameter, but they are called in the template (for whatever reason). I don't mean the "private ones". I'd expected, that Smarty would silently ignore this as with unassigned variables.
3.) the variable passed as the 2nd paramater to be the smarty-reference ($bar in the exmples)
a) where does this $bar come from and where will it finally end?
b) may I just use any name for this?
c) Why do I have to pass it at all?
4.) are there any impacts on caching/compilation, when I call an object method if
a) the method creates a new var with $smarty->assign('newVar', 123)
b) the method reassigns the value of an already defined var
c) creates output *not* passed to smarty, e.g. a plain vanilla echo.
Thanks in advance.
CirTap |
|
Back to top |
|
messju Administrator
Joined: 16 Apr 2003 Posts: 3336 Location: Oldenburg, Germany
|
Posted: Thu Aug 07, 2003 8:47 pm Post subject: Re: Need some info on register_object() |
|
|
CirTap wrote: | 1.) can someone explain to me what "the traditional object parameter format" is supposed to be? Except for the boolean, I can find no difference in the function call and there's no example given to illustrate the difference in the template.
|
the "normal" function format is like a custom-function-plugin:
function meth1($params, &$smarty) {...
in contrast: the "traditional" function format is like the one for assigned objects:
function meth1($p1, $p2) {...
the attribute names are lost and the attribute values are passed in the order they are found in the template AFAIR.
Quote: |
2.) how do I prevent Smarty from throwing an error and stop execution if I give a list of allowed methods/properties as the third parameter, but they are called in the template (for whatever reason). I don't mean the "private ones". I'd expected, that Smarty would silently ignore this as with unassigned variables.
|
you can't. kick the guys that wrote the broken template so they happily fix it.
Quote: |
3.) the variable passed as the 2nd paramater to be the smarty-reference ($bar in the exmples)
a) where does this $bar come from and where will it finally end?
b) may I just use any name for this?
c) Why do I have to pass it at all?
|
don't mix this. both parameters "p1" and "p2" are key-value pairs in $params. it doesn't matter how many attributes your method-call has, you'll always have two parameters (except for "traditional" method call, see above): one for the params and one is the smarty object, the one you call the display()-method off to get the object going in the first place and also the one the object is registered to.
Quote: |
4.) are there any impacts on caching/compilation, when I call an object method if
a) the method creates a new var with $smarty->assign('newVar', 123)
b) the method reassigns the value of an already defined var
c) creates output *not* passed to smarty, e.g. a plain vanilla echo.
|
no there shouldn't be any impact with a) and b).
c) is not encouraged so maybe the output is not always at the place on every version of smarty, but i didn't notice any problems with it.
btw: if the page was cached the object isn't touched anymore and does not even have to be registered.
hth |
|
Back to top |
|
CirTap Smarty Pro
Joined: 04 Jun 2003 Posts: 106
|
Posted: Thu Aug 07, 2003 9:46 pm Post subject: |
|
|
Hi messju,
thanx for this quick reply!
Quote: | the "normal" function format is like a custom-function-plugin:
function meth1($params, &$smarty) {...
in contrast: the "traditional" function format is like the one for assigned objects:
function meth1($p1, $p2) {...
|
I guess I got in trouble with the "two params only" examples.. so this means, if I have:
Quote: | {myobject->myfunc eins="gaga" zwei="foo" drei="bar"} |
the "traditional" call requires the method to accept *three* arguments:
[php:1:a5b7d3da16]function myfunc($arg1, $arg2, $arg3)
// $arg1 ='gaga', $arg2='foo' and $arg3='bar'[/php:1:a5b7d3da16]
wheras when I decide to use the sophisticated Smarty style
Quote: | function myfunc($params, &$smarty_obj) |
I'll have $params['eins'], $params['zwei'], $params['drei']
and this p2=$bar thing from the example would then just contain the same value as $smarty->_tpl_vars['bar'], and appear as a copy(?) in $params['p2'] ?
If I'm right one should provide a clearer "three arguments" example in the docs and how the three finally appear in $params, to actually "see" the difference I would require some annoying debugging sessions to find this out just by the examples.
And I'm still stuck by the term "the format of assigned objects"? I know assign() and assign_by_ref() but not "assign_object()"
Pleeeze, what do you mean?
Quote: | you can't. kick the guys that wrote the broken template so they happily fix |
well, that would be mw No, just kidding. I just tried the examples and as a test I simply called a disallowed function. I don't think it's a good idea that Smarty starts yelling out loud and finaly dies. Consider some huge and complex project, where you find that some "API" might need to change or a method is suddently dicovered to be "insecure". I could just remove it from the "good list" and then - if times allowes - fix the templates, now I would either need to take the site "down" or live with a security hole I'm aware of until I'm able to reviewd a zillion templates.
I may not even be able to place a dummy method in the class. I see some inconsitency in Smarty's behaviour with unassigned vars and this - there should be no difference.
t.i.a
CirTap |
|
Back to top |
|
messju Administrator
Joined: 16 Apr 2003 Posts: 3336 Location: Oldenburg, Germany
|
Posted: Thu Aug 07, 2003 9:59 pm Post subject: |
|
|
- yes all params are passed as copy not as reference to your methods.
- regarding "the format of assigned objects": it simply means you can assign an object as any other variable with $smarty->assign() and call it's methods with {$obj->meth($param)} (note the $-sign before "obj" in contrast to registered objects which have no $-sign).
- you are right and maybe i update the docs with better examples some day, but maybe not before 2.6.0-RC1
(i happily accept patches to the cvs-version of the docs though ) |
|
Back to top |
|
CirTap Smarty Pro
Joined: 04 Jun 2003 Posts: 106
|
Posted: Thu Aug 07, 2003 10:59 pm Post subject: |
|
|
re,
excellent, so i didn't miss any hidden assign-function
I think I like the non-$ form better, even for properties.
I'll use this for the "master objects":{Auth->grants} instead of {$AUTH->grants} Looks more like "this is a special thing, feel honored to use it"
Too bad, I haven't seen this before <piens>
Quote: | maybe i update the docs with better examples some day, but maybe not before 2.6.0-RC1 |
yeah, sure -- the magic words: "some day" I also do a lot of things... some day <gg>
I made a mental note on the syntax, that will recall when I see this again in the manual.
Thanx for your patience, messju: you made my day! err: night.
n8
CirTap |
|
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
|
|