相關知識:
1、2、模板引擎Smarty深入淺出介紹Smarty技術是PHP的精髓所在, 隨著PHP版本的逐漸提高,原來的很多方法也許太過時了,下面我就針對最新的PHP5.1.1版本的使用,配置說說如何配置。下面是一步步的來的,請注重:1、在官方下載模板庫檔案:下載了就解壓,看見一個檔案夾了,是個smarty.x.x,開啟,裡面有個libs檔案夾,ok,注重這個東西就是我們要的。2、在你的網站目錄下面,比方我的php網站IIS在物理硬碟的d:/web/web/php下面,在這個檔案夾下面建立:一個檔案夾test,然後我們把剛提到的 libs檔案夾複製道test檔案夾下面。 * 請看本文最後的注釋 Tips13、在test檔案夾下面再建立4個檔案夾:
cache
configs
templates
templates
_c4、建立檔案text.htm:<$content>儲存在templates目錄下面。5、然後建立檔案模板設定檔: config.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->center_delimiter = <;
$tpl->center_delimiter =>;?>儲存在主目錄也就是test下面。6、在test建立檔案test.php檔案,輸入:
require config.php;
$tpl->assign(title, 測試成功了,這是標題);
$tpl->assign(content, 這是內容);
$tpl->display(test.htm);?>7、在瀏覽器測試test.php顯示為:這是內容恭喜,配置成功.否則,失敗,再檢查是不是按照我說的來的。
Tips1
:為了能在網站全域使用Smarty技術,我們可以修改PHP.inc裡面的;Windows:path1;path2include_path = .;c:phpincludes改為:;Windows:path1;path2include_path=.;c:php includes;d:webwebphplibs使用模板的時候,像前面一樣的方式使用,不要:include.. /libs/Smarty.class.php;直接使用就行了的。