使用 $smarty->register_object 报错解决方案
程序员文章站
2022-04-27 23:46:09
...
使用 $smarty->register_object 报错
本人php
require("libs/Smarty.class.php");
$smarty = new Smarty;
$smarty->template_dir = "templates";
$smarty->cache_dir = "cache";
$smarty->config_dir = "configs";
$smarty->compile_dir = "templates_c";
class My_Object
{
function meth1($params, &$smarty_obj)
{
return "this is my meth1";
}
}
$myobj = new My_Object;
// registering the object (will be by reference)
$smarty->register_object("foobar",$myobj);
$smarty->display('eg_15_1.tpl');
?>
报错如下:
Fatal error: Uncaught exception 'SmartyException' with message 'Call of unknown method 'register_object'.' in D:\xampp\htdocs\smarty\libs\sysplugins\smarty_internal_templatebase.php:806 Stack trace: #0 D:\xampp\htdocs\smarty\eg_15_1.php(22): Smarty_Internal_TemplateBase->__call('register_object', Array) #1 D:\xampp\htdocs\smarty\eg_15_1.php(22): Smarty->register_object('foobar', Object(My_Object)) #2 {main} thrown in D:\xampp\htdocs\smarty\libs\sysplugins\smarty_internal_templatebase.php on line 806
麻烦熟悉的朋友帮忙看下。。。
------解决方案--------------------
register_object===>assign
本人php
require("libs/Smarty.class.php");
$smarty = new Smarty;
$smarty->template_dir = "templates";
$smarty->cache_dir = "cache";
$smarty->config_dir = "configs";
$smarty->compile_dir = "templates_c";
class My_Object
{
function meth1($params, &$smarty_obj)
{
return "this is my meth1";
}
}
$myobj = new My_Object;
// registering the object (will be by reference)
$smarty->register_object("foobar",$myobj);
$smarty->display('eg_15_1.tpl');
?>
报错如下:
Fatal error: Uncaught exception 'SmartyException' with message 'Call of unknown method 'register_object'.' in D:\xampp\htdocs\smarty\libs\sysplugins\smarty_internal_templatebase.php:806 Stack trace: #0 D:\xampp\htdocs\smarty\eg_15_1.php(22): Smarty_Internal_TemplateBase->__call('register_object', Array) #1 D:\xampp\htdocs\smarty\eg_15_1.php(22): Smarty->register_object('foobar', Object(My_Object)) #2 {main} thrown in D:\xampp\htdocs\smarty\libs\sysplugins\smarty_internal_templatebase.php on line 806
麻烦熟悉的朋友帮忙看下。。。
------解决方案--------------------
register_object===>assign
相关文章
相关视频
推荐阅读
-
MySQL使用GROUP BY分组查询报错 ,ONLY_FULL_GROUP_BY解决方案
-
使用spring-data-jpa进行count时报错No property count found for type xxx的解决方案
-
Nodejs使用archiver-zip-encrypted库加密压缩文件时报错(解决方案)
-
Twistedadbapi使用mysql时提示报错及解决方案分享
-
使用uview插件时报错 ‘文件查找失败’解决方案
-
Jupyter Notebook内使用argparse报错的解决方案
-
使用Sqlyog远程连接数据库报错解决方案
-
php使用memcache存储session时报错解决方案
-
VS使用scanf出现报错的情况及解决方案
-
Python3 fake_useragent 模块的使用和报错解决方案