今天第一次写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 PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<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文件放在根目录所以就会出现这种问题.
我想大家应该也知道问题出现在哪里了吧