Fatal error: Uncaught exception 'SmartyException' with message 'Call of unknown function 'templates'.' in D:phpStudyWWWblog1includessmartySmarty.class.php:782 Stack trace: #0 D:phpStudyWWWblog1includesinit.php(23): Smarty->__call('templates', Array) #1 D:phpStudyWWWblog1includesinit.php(23): Smarty->templates('D:\phpStudy\WWW...') #2 D:phpStudyWWWblog1index.php(2): require_once('D:\phpStudy\WWW...') #3 {main} thrown in D:phpStudyWWWblog1includessmartySmarty.class.php on line 782
define('THEMES_DEFAULT',ROOT."/themes/default/");
$smarty = new Smarty(); //建立smarty实例对象$smarty
$smarty->templates(THEMES_DEFAULT."templates"); //设置模板目录
$smarty->assign("name", "hardprodog"); //进行模板变量替换
$smarty->display("index.htm"); //编译并显示位于./templates下的index.htm模板
模板路径没有写错,请问为什么会出现这个报错?
$smarty->template_dir 替换 $smarty->templates()
题主在设置模板目录时调用的方法错误。
正确调用的方法应是:
$smarty = new Smarty();
$smarty->setTemplateDir('./your-templates-dir');
建议打断点 检查问题。