久违的Smarty又派上用场了,,
翻阅了一下以前的日志,居然没有Smarty的配置说明,so,这就补上一篇~!
Smarty配置的步骤:
1、从官方网站下载Smarty包: http://smarty.php.net/download.php,最新版本是2.6.19,
下载并解压缩后,将Smarty-2.6.19打开,libs文件夹里面的东西就是我们需要的。
2、在你的网站目录下面,比如你的站点文件夹名称是gtv.com,那么请将你libs文件夹拷贝到这个目录下面。
* 请看本文最后的注释 TIPS1
3、在gtv.com下面再新创建4个文件夹:
cache
configs
templates
templates_c
4、建立文件 test.htm,保存在 templates 目录下面。
5、然后建立文件模板配置文件: config.php,保存在主目录也就是gtv.com下面。
6、在gtv.com新建文件test.php文件,输入:
7、在浏览器测试test.php显示为:
恭喜,配置成功.否则,失败,再检查是不是按照我说的来的。
Tips1 :为了能在网站全局使用Smarty技术,我们可以修改PHP.inc里面的
改为:
使用模板的时候,像前面一样的方式使用,不要:
直接使用就行了的。
翻阅了一下以前的日志,居然没有Smarty的配置说明,so,这就补上一篇~!
Smarty配置的步骤:
1、从官方网站下载Smarty包: http://smarty.php.net/download.php,最新版本是2.6.19,
下载并解压缩后,将Smarty-2.6.19打开,libs文件夹里面的东西就是我们需要的。
2、在你的网站目录下面,比如你的站点文件夹名称是gtv.com,那么请将你libs文件夹拷贝到这个目录下面。
* 请看本文最后的注释 TIPS1
3、在gtv.com下面再新创建4个文件夹:
cache
configs
templates
templates_c
4、建立文件 test.htm,保存在 templates 目录下面。
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>{$title}</title>
</head>
<body>
{$content}
</body>
</html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>{$title}</title>
</head>
<body>
{$content}
</body>
</html>
5、然后建立文件模板配置文件: config.php,保存在主目录也就是gtv.com下面。
<?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 = '}';
?>
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 = '}';
?>
6、在gtv.com新建文件test.php文件,输入:
<?php
require "config.php";
$tpl->assign("title", "测试成功了,这是标题");
$tpl->assign("content", "这是内容");
$tpl->display('test.htm');
?>
require "config.php";
$tpl->assign("title", "测试成功了,这是标题");
$tpl->assign("content", "这是内容");
$tpl->display('test.htm');
?>
7、在浏览器测试test.php显示为:
这是内容
恭喜,配置成功.否则,失败,再检查是不是按照我说的来的。
Tips1 :为了能在网站全局使用Smarty技术,我们可以修改PHP.inc里面的
; Windows: "/path1;/path2"
include_path = ".;d:/php/includes"
include_path = ".;d:/php/includes"
改为:
; Windows: "/path1;/path2"
include_path = ".;d:/php/includes;d:/web/gtv.com/libs"
include_path = ".;d:/php/includes;d:/web/gtv.com/libs"
使用模板的时候,像前面一样的方式使用,不要:
include "libs/Smarty.class.php";
直接使用就行了的。