路径很关键。
可以不确定的时候先用echo 打印出来,看看路径是否正确。
我的服务器目录是D:/xampp/htdocs;
文件目录如下:
config.php内容如下
<?php
define('BASE_PATH',$_SERVER['DOCUMENT_ROOT']);//D:/xampp/htdocs
define('SMARTY_PATH', '/SmartyTest/Smarty/');//D:/xampp/htdocs/SmartyTest/Smarty/
require BASE_PATH.SMARTY_PATH.'Smarty.class.php';
$smarty=new Smarty();
$smarty->template_dir='./Smarty/templates/';
$smarty->compile_dir='./Smarty/templates_c/';
$smarty->config_dir='./Smarty/configs/';
$smarty->cache_dir='./Smarty/cache/'
?>
index.php的内容如下,关键要写清include的地址
<?php
header("Content-type:text/html;charset=UTF-8");
include("Smarty/configs/config.php");//关键
$smarty->assign('title','第一个smarty程序');
$smarty->assign('content','hello world');
$smarty->display('index.html');
?>
templates文件夹下面有一个 index.html。
<html>
<title>{$title}</title>
<body>
<p>{$content}</p>
</body>
</html>
访问的时候输入:http://localhost/SmartyTest/index.php即可