>  기사  >  백엔드 개발  >  使用 $smarty->register_object 报错解决方案

使用 $smarty->register_object 报错解决方案

WBOY
WBOY원래의
2016-06-13 10:20:23983검색

使用 $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

성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.