笑談配置,使用Smarty技術(shù)
更新時(shí)間:2007年01月04日 00:00:00 作者:
Smarty技術(shù)是PHP的精髓所在,隨著PHP版本的逐漸提高,原來的很多方法也許太過時(shí)了,下面我就針對最新的PHP5.1.1版本的使用,配置說說如何配置.
下面是一步步的來的,請注意:
1: 在官方下載模板庫文件: http://smarty.php.net/download.php
下載了就解壓,看見一個(gè)文件夾了,是個(gè) smarty.x.x,打開,里面有個(gè)libs 文件夾,ok,注意這個(gè)東西就是我們要的.
2: 在你的網(wǎng)站目錄下面,比方我的php網(wǎng)站IIS在物理硬盤的 d:/web/web/php下面,在這個(gè)文件夾下面建立:一個(gè)文件夾 test,然后我們把剛提到的 libs文件夾復(fù)制道test 文件夾下面.{ * 請看本文最后的注釋 TIPS1}
3:在test 文件夾下面再建立4個(gè)文件夾;
cache
configs
templates
templates_c
4:建立文件 text.htm:
保存在 templates 目錄下面.
5:然后建立文件模板配置文件: config.php
保存在主目錄也就是 test下面.
6 :在test新建文件test.php文件,輸入:
7:在瀏覽器測試test.php顯示為:
這是內(nèi)容
恭喜,配置成功.否則,失敗,再檢查是不是按照我說的來的.
Tips1 :為了能在網(wǎng)站全局使用Smarty技術(shù),我們可以修改PHP.inc里面的
<B>
; Windows: "path1;path2"
include_path = ".;c:phpincludes"
</B>
改為:
------------------->
; Windows: "path1;path2"
include_path = ".;c:phpincludes;d:webwebphplibs"
使用模板的時(shí)候,像前面一樣的方式使用,不要
include "../libs/Smarty.class.php";
直接使用就行了的.
下面是一步步的來的,請注意:
1: 在官方下載模板庫文件: http://smarty.php.net/download.php
下載了就解壓,看見一個(gè)文件夾了,是個(gè) smarty.x.x,打開,里面有個(gè)libs 文件夾,ok,注意這個(gè)東西就是我們要的.
2: 在你的網(wǎng)站目錄下面,比方我的php網(wǎng)站IIS在物理硬盤的 d:/web/web/php下面,在這個(gè)文件夾下面建立:一個(gè)文件夾 test,然后我們把剛提到的 libs文件夾復(fù)制道test 文件夾下面.{ * 請看本文最后的注釋 TIPS1}
3:在test 文件夾下面再建立4個(gè)文件夾;
cache
configs
templates
templates_c
4:建立文件 text.htm:
復(fù)制代碼 代碼如下:
<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>
保存在 templates 目錄下面.
5:然后建立文件模板配置文件: config.php
復(fù)制代碼 代碼如下:
<?php
include "../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 = '}>';
?>
include "../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 = '}>';
?>
保存在主目錄也就是 test下面.
6 :在test新建文件test.php文件,輸入:
復(fù)制代碼 代碼如下:
<?php
require "config.php";
$tpl->assign("title", "測試成功了,這是標(biāo)題");
$tpl->assign("content", "這是內(nèi)容");
$tpl->display('test.htm');
?>
require "config.php";
$tpl->assign("title", "測試成功了,這是標(biāo)題");
$tpl->assign("content", "這是內(nèi)容");
$tpl->display('test.htm');
?>
7:在瀏覽器測試test.php顯示為:
這是內(nèi)容
恭喜,配置成功.否則,失敗,再檢查是不是按照我說的來的.
Tips1 :為了能在網(wǎng)站全局使用Smarty技術(shù),我們可以修改PHP.inc里面的
<B>
; Windows: "path1;path2"
include_path = ".;c:phpincludes"
</B>
改為:
------------------->
; Windows: "path1;path2"
include_path = ".;c:phpincludes;d:webwebphplibs"
使用模板的時(shí)候,像前面一樣的方式使用,不要
include "../libs/Smarty.class.php";
直接使用就行了的.
相關(guān)文章
php Http_Template_IT類庫進(jìn)行模板替換
php Http_Template_IT模板替換實(shí)現(xiàn)代碼2009-03-03