|
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 |
gerard Smarty Regular
Joined: 18 Apr 2003 Posts: 84
|
Posted: Fri Jan 02, 2004 10:13 pm Post subject: register_object in plugin |
|
|
I'm trying to write a plugin that will create and register an object.
Code: | function smarty_function_get_object($params, &$smarty) {
extract($params);
if (empty($var)) {
$smarty->trigger_error("assign: missing 'var' parameter");
return;
}
if (empty($file)) {
$smarty->trigger_error("assign: missing 'file' parameter");
return;
}
if (empty($class)) {
$smarty->trigger_error("assign: missing 'class' parameter");
return;
}
include_once($file);
$obj = new $class;
$smarty->assign_by_ref($var, $obj);
$smarty->register_object($var, $obj);
} |
Code: | {get_object var="otest" class="test" file="class.test.php"}
{$otest->print_test()}
{otest->print_test}
|
The "{$otest->print_test()}" in the template works, but "{otest->print_test}" gives an "Fatal error: Smarty error: registered 'otest' is not an object in Smarty.class.php on line 2654" error. Any idea what the problem is? Variable scope in functions perhaps? I tried making the object global in the plugin function. Is this sort of function even possible with register_object? |
|
Back to top |
|
messju Administrator
Joined: 16 Apr 2003 Posts: 3336 Location: Oldenburg, Germany
|
Posted: Sat Jan 03, 2004 12:01 am Post subject: |
|
|
i think what you try is not possible because the object has to be registered at the time the template is compiled. that basically means it has to be registered before you call $smarty->fetch() or $smarty->display() . |
|
Back to top |
|
gerard Smarty Regular
Joined: 18 Apr 2003 Posts: 84
|
Posted: Sat Jan 03, 2004 1:55 am Post subject: |
|
|
Ah, would've have been a while before I figured that out. Is there any way to hack around it? Or, just so both object syntaxes will work in templates? |
|
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
|