View previous topic :: View next topic |
Author |
Message |
fduarte42 Smarty Rookie
Joined: 09 May 2003 Posts: 8
|
Posted: Wed Dec 17, 2003 11:26 am Post subject: register_block() with create_function doesn't work in 2.6.0 |
|
|
I upgraded my smarty release to 2.6.0 (from 2.5.0) and now $smarty->register_block() using a temporary function (create_function) doesn't work anymore.
It doesn't matter wether I cache the plugin or not.
What happens is:
Fatal error: Call to undefined function: lambda_29721() in (...)Test.tpl.php on line 5
the compile_block function does get the right function and is_callable is true.
What is the difference to the 2.5.0 implementation?
thx for your help.
Tito |
|
Back to top |
|
messju Administrator
Joined: 16 Apr 2003 Posts: 3336 Location: Oldenburg, Germany
|
Posted: Wed Dec 17, 2003 12:19 pm Post subject: Re: register_block() with create_function doesn't work in 2. |
|
|
fduarte42 wrote: | What is the difference to the 2.5.0 implementation? |
the difference is, that the function-calls are compiled literally into the templates.
with register_block('plugin_name', 'function_name')
in 2.5.0 the function-call was sth. like:
$this->_plugins['block']['plugin_name'][0]($params)
in 2.6.0 it's
function_name($params)
create_function() returns a function-name that contains a null-byte as the first character (!). this braindeadness makes your construct break in 2.6.0 .
see also: http://bugs.php.net/bug.php?id=10721 |
|
Back to top |
|
fduarte42 Smarty Rookie
Joined: 09 May 2003 Posts: 8
|
Posted: Wed Dec 17, 2003 1:11 pm Post subject: |
|
|
What is the reason for changing that? Did you have any problems with the original construct?
I need the create_function construct, cause I have dynamically created block tags that must be parsed.
The new construct has also the oddity, that I got to recompile the template to get the new tempory function name.
Is their a possiblity to make this work, like it worked in 2.5.0?
thx for your support
Tito |
|
Back to top |
|
messju Administrator
Joined: 16 Apr 2003 Posts: 3336 Location: Oldenburg, Germany
|
Posted: Wed Dec 17, 2003 1:35 pm Post subject: |
|
|
fduarte42 wrote: | What is the reason for changing that? Did you have any problems with the original construct? |
the new way is faster and the old way doesn't work with php5. |
|
Back to top |
|
fduarte42 Smarty Rookie
Joined: 09 May 2003 Posts: 8
|
Posted: Wed Dec 17, 2003 1:37 pm Post subject: |
|
|
What should I do? Do you have a Solution or a hint?
thx |
|
Back to top |
|
messju Administrator
Joined: 16 Apr 2003 Posts: 3336 Location: Oldenburg, Germany
|
Posted: Wed Dec 17, 2003 1:45 pm Post subject: |
|
|
you can use eval() instead of create_function() to get sane function-names. or you can wrap the call to the created function:
something like:
[php:1:c6bc7cf7eb]function smarty_block_foo($params, $content, &$smarty, &$repeat) {
$funcname = $smarty->get_template_vars('func_foo');
return $funcname($params, $content, $smarty, $repeat);
}
...
$smarty->assign('func_foo', create_function(...));[/php:1:c6bc7cf7eb] |
|
Back to top |
|
fduarte42 Smarty Rookie
Joined: 09 May 2003 Posts: 8
|
Posted: Wed Dec 17, 2003 2:09 pm Post subject: |
|
|
thx for your help. I solved the problem by using one function.
To know for which block it was called, i use the following code:
Code: |
$tag = end($smarty->_tag_stack);
$widget = $tag[0]; |
The block function looks like this:
Code: | function block_Wack($params, $content, &$smarty, &$repeat){
if (!isset($content)) {
$tag = end($smarty->_tag_stack);
$widget = $tag[0];
$end = count($smarty->_widget_stack);
$smarty->_widget_stack[$end] =& Factory::makeWidgetController($this->_controller, $this->_module, $widget,$params,$smarty);
$smarty->_widget_stack[$end]->processEvents();
} else {
$end = count($smarty->_widget_stack);
$smarty->_widget_stack[$end-1]->display($content);
unset($smarty->_widget_stack[$end-1]);
}
} |
|
|
Back to top |
|
boots Administrator
Joined: 16 Apr 2003 Posts: 5611 Location: Toronto, Canada
|
Posted: Wed Dec 17, 2003 5:44 pm Post subject: |
|
|
wow, lambda function as registered plugin--kind of goes against the idea of the function being anonymous, yes?
Another suggestion is to write a PHP code template which could then be included (though you will have to determine the auto file name). I wrote a simple stream wrapper to automate tasks like this for me. |
|
Back to top |
|
|