I found this message on php-general list, and I'm cross-posting the
reply to Smarty list.
I see a couple of issues with passing Smarty object to modifiers.
1. You want to use _current_file and _current_lineno member variables,
but they are only defined in Smarty_Compiler class, and what actually
runs the modifiers is Smarty class. Check Smarty::_run_mod_handler().
2. The only reasonable way to make Smarty object available to modifiers
is to pass it as a last parameter. However, you run into problems when
your modifier has default parameters. For example:
function x_mod($arg1, $arg2 = 5, &$smarty)
{
...
}
If you call modifier as {$foo|x}, $arg2 would actually point to the
Smarty object, and you will get a notice complaining about $smarty
parameter not being passed. So, it would not be possible to use default
parameters for modifiers which is a big step back IMO.
Can you provide alternative ideas?
> Hi,
>
> is there a way to access the calling smarty object from withing a
> modifier callback function?
>
> Regular smarty callback functions get passed a list of "parameters" of
> the function call as a first argument and a reference to the calling
> smarty object as a second argument.
>
> function my_smary_func($params, &$smarty) {
> ...
>
> if (my_smarty_check_params($params, $allowed)) {
> return true;
> }
>
> $smarty->assign();
> ...
> }
>
>
> That way you can not only modify the smarty object but access properties
> of the object. Two of them help me to generate error messages:
> $smarty->_current_line_no and $smarty->_current_file (btw. one should
> "make them public").
>
> function my_smarty_check_params($params, $allowed, &$smarty) {
> ....
> if (...) {
> return sprintf("Error on %s %d", $smarty->_current_file, ...);
> }
> ...
> }
>
> Can I do something similar with modifiers, which seem to have this
> format. Is there a way to access the calling smarty object?
>
> function my_smarty_modifier($value, $option = '', ...) {
> ??? $smarty->... ???
> }
-Andrei
When we eliminate the impossible, whatever remains,
however improbable, must be true. -- Sherlock Holmes
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]