主選單FreeBSD
PcBSD 0.83Windows程式語言(edit)
|
Smarty 是 PHP 的範本之一, 想對他有更深入的了解請上 http://smarty.php.net/
安裝環境 FreeBSD 5.3 + Apache 1.3 + PHP 4.11Step.1 安裝 Smarty# cd /usr/ports/www/smarty # make installStep.2 修改 php.ini 若在 /usr/local/etc 中找不到 php.ini 請將 php.ini-dist 複製成 php.ini 編輯此檔加上 include_path = ".:/usr/local/share/smarty"Step.3 建立相關目錄、變更權限 # cd /usr/local/www/data # mkdir templates; mkdir templates_c;mkdir configs;mkdir cache # chown nobody:nobody templates_c;chown nobody:nobody cache # chmod 777 templates_c;chmod 777 cache ? 根據手冊上寫的 770 權限,沒辦法正常運作Step.4 啟動 Apache # /usr/local/sbin/apache startStep.5 測試 smarty a. 編輯 hello.php <?
require("Smarty.class.php");
$tpl = new Smarty();
$tpl->assign("title", "我的第一個 smarty 程式");
$tpl->assign("content", "Hello world!!");
$tpl->display('hello.htm');
?>
b. 編輯 hello.htm (此檔需放在 templates 目錄中) <html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=big5">
<title>{$title}</title>
</head>
<body>
{$content}
</body>
</html>
編輯完後,打開流灠器輸入網址與檔名 (hello.php) 就可以看到結果了。 |