smarty配置

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模板 

模板路径没有写错,请问为什么会出现这个报错?

阅读 3.4k
3 个回答

建议打断点 检查问题。

$smarty->template_dir 替换 $smarty->templates()

新手上路,请多包涵

题主在设置模板目录时调用的方法错误。

正确调用的方法应是:

$smarty = new Smarty();
$smarty->setTemplateDir('./your-templates-dir');
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进