下面我对最新的PHP5版本的使用,如何配置
Smarty1、在官方下载模板库文件: http://smarty.php.net/download.php
下载了就解压,看见一个文件夹了,是个 smarty.x.x,打开,里面有个libs 文件夹,ok2、在你的网站目录下面,比方我的php网站IIS在物理硬盘的 E:/smarty/下面,在这个文件夹下面建立:一个文件夹 test,然后我们把刚解压的smarty文件夹复制到 test 文件夹下面。3、在test 文件夹下面再建立4个文件夹:
cache
configs
templates
templates_c
4、现在TEST文件夹里面有这几个文件夹
cache
configs
templates
templates_c
Smarty
5、建立文件 test.htm 保存在 templates 文件夹下面
test.htm:
<//html>
<//head>
<//meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<//title><{$title}><///title>
<///head>
<//body>
<//{$content}>
<///body>
<///html>由于百度代码过滤复制test.htm代码过后请将<后的//删除,记住是“//”
6、然后建立文件模板配置文件: config.php 保存在test文件夹下
config.php:
<?php
include "smarty/libs/Smarty.class.php";
$NowPathArray=explode("test",str_replace("\\","/",dirname(__FILE__))) ;
@define("root_path", $NowPathArray[0]);
@define('__SITE_ROOT', root_path."test");
$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 = '}>';
?>7、继续建立文件test.php文件,同样保存在 test文件夹下
test.php:
<?php
require "config.php";
$tpl->assign("title", "测试成功了,这是标题");
$tpl->assign("content", "测试结果成功");
$tpl->display('test.htm');
?>
8、在浏览器测试test.php显示结果:(http://localhost/smarty/test/test.php)因个人电脑配置而定test.php结果:测试结果成功9、配置成功。附:为了能在网站全局使用Smarty技术,我们可以修改PHP.inc里面的
; Windows: "\path1;\path2"
include_path = ".;c:\php\includes" 修改成为: ; Windows: "\path1;\path2"
include_path = ".;c:\php\includes;E:\smarty\test\Smarty\libs"
10、检查文件夹内的目录:
test文件夹内包含:
cache
configs
templates
templates_c
Smarty
config.php
test.php
即为正解;
12、检查templates_c文件夹下是否包含一个例如“%%179”文件名的文件夹
11、收工。