Warning: Smarty error: unable to read resource
今天第一次写smarty就出来这样的提示:Warning: Smarty error: unable to read resource,代码如下
<?php include_once("Smarty/libs/Smarty.class.php"); $smarty =new Smarty(); $smarty->template_dir ='Smarty/template'; $smarty->compile_dir ='Smarty/template_c'; $smarty->left_delimiter ='<{'; $smarty->right_delimiter='}>'; $smarty->assign('first','第一个'); $smarty->display('one.tpl'); ?>
one.tpl文件如下:
<!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> <title>无标题文档</title> </head> <body> <{include file="head.tpl"}> this is my the <{$first}> smarty! <{include file="bot.tpl"}> </body> </html>
head.tpl和bot.tpl文件是头部和尾部文件,这个有一点像asp里面的include的调用外部文件的方式,
看上去代码很简单但怎么会出来这种问题呢?仔细查看后发原来是one.tpl 文件没有放到template目录下,为什么一定要放在这个目录下呢?好我们来看上面的一代码, $smarty->template_dir ='Smarty/template';仔细一看才明白 template是设计模板文件所在的目录,因为我one.tpl文件放在根目录所以就会出现这种问题.
我想大家应该也知道问题出现在哪里了吧
本文链接:http://www.phprm.com/frame/bf990f599cdbb5e54053406a2ee067b9.html
收藏随意^^请保留教程地址.