1.在www.smarty.net 下载smarty,解压 。假设解压目录为Smarty-2.6.19。
2.在网站主目录下建立文件夹smartytest(比如:XAMPP下 E:/xampp/htdocs/smartytest) 同时在 smartytest目录下建立如下几个目录:cache ,configs ,templates, templates_c。并且将Smarty-2.6.19下libs目录全部复制到smartytest目录下。
3.将以下代码保存到config.php中 并将文件保存到 smartytest下(smartytest/config.php)
<?php
include "libs/Smarty.class.php";
@define('__SITE_ROOT', str_replace("//","/",dirname(__FILE__)));
$tpl = new Smarty();
$tpl->template_dir = __SITE_ROOT . "/templates/";
$tpl->compile_dir = __SITE_ROOT . "/templates_c/";
$tpl->config_dir = __SITE_ROOT . "/configs/";
$tpl->cache_dir = __SITE_ROOT . "/cache/";
$tpl->left_delimiter = '<{';
$tpl->right_delimiter = '}>';
?>
4. 修改php.ini中(我的是XAMPP 修改的是php/php5.ini和apache/bin/php.ini)
; Windows: "/path1;/path2"
include_path = ".;E:/xampp/php/pear/;E:/xampp/htdocs/smartytest/libs" (指向smartytest 中的libs 绝对路径).
改后 重启apache.
5.测试:将以下代码保存到 test.php 中 smartytest/test.php
<?php
require "config.php";
$tpl->assign("title", "测试成功了,这是标题");
$tpl->assign("content", "这是内容");
$tpl->display('test.html');
?>
将以下代码保存 test.html中 smartytest/templates/test.html
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title><{$title}></title>
</head>
<body>
<{$content}>
</body>
</html>
6.运行test.php 文件(XAMPP下 http://localhost/smartytest/test.php)
2.在网站主目录下建立文件夹smartytest(比如:XAMPP下 E:/xampp/htdocs/smartytest) 同时在 smartytest目录下建立如下几个目录:cache ,configs ,templates, templates_c。并且将Smarty-2.6.19下libs目录全部复制到smartytest目录下。
3.将以下代码保存到config.php中 并将文件保存到 smartytest下(smartytest/config.php)
<?php
include "libs/Smarty.class.php";
@define('__SITE_ROOT', str_replace("//","/",dirname(__FILE__)));
$tpl = new Smarty();
$tpl->template_dir = __SITE_ROOT . "/templates/";
$tpl->compile_dir = __SITE_ROOT . "/templates_c/";
$tpl->config_dir = __SITE_ROOT . "/configs/";
$tpl->cache_dir = __SITE_ROOT . "/cache/";
$tpl->left_delimiter = '<{';
$tpl->right_delimiter = '}>';
?>
4. 修改php.ini中(我的是XAMPP 修改的是php/php5.ini和apache/bin/php.ini)
; Windows: "/path1;/path2"
include_path = ".;E:/xampp/php/pear/;E:/xampp/htdocs/smartytest/libs" (指向smartytest 中的libs 绝对路径).
改后 重启apache.
5.测试:将以下代码保存到 test.php 中 smartytest/test.php
<?php
require "config.php";
$tpl->assign("title", "测试成功了,这是标题");
$tpl->assign("content", "这是内容");
$tpl->display('test.html');
?>
将以下代码保存 test.html中 smartytest/templates/test.html
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title><{$title}></title>
</head>
<body>
<{$content}>
</body>
</html>
6.运行test.php 文件(XAMPP下 http://localhost/smartytest/test.php)