我在学习 PHP模板引擎Smarty入门使用 时都是按照教程里讲的做的,但在执行index.php时还是提示:Warning: Smarty error: u
nable to read resource: "index.htm" in D:\wamp\www\moban\smarty\Smarty.class.php on line 1095
不知道是smarty出了问题还是程序编错了,请大家帮我看一下。
111111111111111111111111111111111111111111111111111111111111111111111111111111111
首先编一个配置文件:smarty_inc.php (我是从教程里复制过来的,另外该新建的路径文件我也建了)。
<?php
include_once("Smarty/Smarty.class.php"); //包含smarty类文件
$smarty = new Smarty(); //建立smarty实例对象$smarty
$smarty->config_dir="Smarty/Config_File.class.php"; // 目录变量
$smarty->caching=false; //是否使用缓存,项目在调试期间,不建议启用缓存
$smarty->template_dir = "./templates"; //设置模板目录
$smarty->compile_dir = "./templates_c"; //设置编译目录
$smarty->cache_dir = "./smarty_cache"; //缓存文件夹
//----------------------------------------------------
//左右边界符,默认为{},但实际应用当中容易与JavaScript相冲突
//----------------------------------------------------
$smarty->left_delimiter = "{";
$smarty->right_delimiter = "}";
?>
11111111111111111111111111111111111111111111111111111111111111111111111111111111111111
22222222222222222222222222222222222222
第二步建一个index.php文件
<?php
include ("smarty_inc.php");
$name="php100中文网站";
$smarty->assign("title",$name);
$smarty->display("index.htm");
?>
22222222222222222222222222222222222222
3333333333333333333333333333333333333333333333333333333333333333333333333333333333333333
第三步要建一个index.htm文件
<html>
<b>{$title}</b>
</html>
33333333333333333333333333333333333333333333333333333333333333333333333333333333333333333
写好之后我执行index.php文件是却提示:
Warning: Smarty error: unable to read resource: "index.htm" in D:\wamp\www\moban\smarty\Smarty.class.php on line 1095
不知道问题究竟出在哪儿!
学习 PHP模板引擎Smarty入门使用 时出错提示:Smarty.class.php on line 1095
答案:2 悬赏:80 手机版
解决时间 2021-03-09 17:35
- 提问者网友:献世佛
- 2021-03-08 20:20
最佳答案
- 五星知识达人网友:白昼之月
- 2021-03-08 21:01
不能“读”取资源 index.htm
smarty读模板动作失败,原因有3
1.index.htm没有读权限,看你新手,应该在win下,排除这个原因
2.没有模板文件不存在,index.htm不存在,这个你自己知道,你肯定建立了这么一个模板
3.模板路径错误,这是你的症结
当你$tpl = new Smarty;之后,推荐打印一下echo $tpl->template_dir;
看看你的index.htm在不在这个目录下
smarty读模板动作失败,原因有3
1.index.htm没有读权限,看你新手,应该在win下,排除这个原因
2.没有模板文件不存在,index.htm不存在,这个你自己知道,你肯定建立了这么一个模板
3.模板路径错误,这是你的症结
当你$tpl = new Smarty;之后,推荐打印一下echo $tpl->template_dir;
看看你的index.htm在不在这个目录下
全部回答
- 1楼网友:狂恋
- 2021-03-08 21:52
一是设置那三目录用
$smarty->template_dir = './templates/';
$smarty->compile_dir = './templates_c/';
$smarty->cache_dir = './cache/'; 并确保这三目录存在并且路径正确.
二是你模板写法有误
应改为
新闻编号:{$newsid.newsid}
新闻内容:{$newsid.newstitle}
三开发期间最好别启用smarty cache 将 $smarty->caching = false;
三开发期间最好别启用smarty cache 将 $smarty->caching = false;
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯