究竟tpl模板文件应放在哪里???

fasva 2012-07-22 10:53:22
PHP文件:

<?php
ob_start('ob_gzhandler');



require('Smarty/libs/Smarty.class.php');

$smarty = new Smarty();


$smarty->assign("title", 'Smarty Rocks!');
$smarty->assign("name", 'Jason Gilmore');

$smarty->display('Smarty/demo/templates/welcome.tpl');
?>


welcome.tpl:

<html>
<head>
<title>{$title}</title>
</head>
<body>
<p>Hi, {$name}. Welcome to the wonderful world of Smarty.</p>
</body>
</html>


运行PHP文件时却显示:

Fatal error: Uncaught exception 'SmartyException' with message 'Unable to load template file 'Smarty/demo/templates/welcome.tpl'' in D:\php5\includes\Smarty\libs\sysplugins\smarty_internal_templatebase.php:127 Stack trace: #0 D:\php5\includes\Smarty\libs\sysplugins\smarty_internal_templatebase.php(374): Smarty_Internal_TemplateBase->fetch('Smarty/demo/tem...', NULL, NULL, NULL, true) #1 D:\Apache Group\Apache2\htdocs\PHPProject\index3.php(15): Smarty_Internal_TemplateBase->display('Smarty/demo/tem...') #2 {main} thrown in D:\php5\includes\Smarty\libs\sysplugins\smarty_internal_templatebase.php on line 127


我用的是zend studio 9,在网站文件夹中的“PHP Include Path”中也导入了Smart\demo\templates(这是welcome.tpl放置的位置,这个Smart在我的D:\php5\includes中)中了,为什么还显示错误?
...全文
377 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
蹲坑看月亮 2012-07-23
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 的回复:]

$smarty->display('Smarty/demo/templates/welcome.tpl');
参数相对而言的

你检测下 Smarty 文件夹下有没 demo 文件夹下有没 templates 文件夹下有没 welcome.tpl 文件
[/Quote]
先找找看看
ayzen1988 2012-07-23
  • 打赏
  • 举报
回复
还有可以设置 模板的 路径
$smarty->addTemplateDir("./Smarty/demo/templates/");
这个是3.1.10版本的
ayzen1988 2012-07-23
  • 打赏
  • 举报
回复
$smarty->display('Smarty/demo/templates/welcome.tpl');
参数相对而言的

你检测下 Smarty 文件夹下有没 demo 文件夹下有没 templates 文件夹下有没 welcome.tpl 文件
kankan231 2012-07-23
  • 打赏
  • 举报
回复
$smarty->display("filepath")这里的filepath是相对模板目录的,假如你把welcome.tpl放在模板目录templates下,那么就是$smarty->display("welcome.tpl")

21,890

社区成员

发帖
与我相关
我的任务
社区描述
从PHP安装配置,PHP入门,PHP基础到PHP应用
社区管理员
  • 基础编程社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧