標籤:style blog http ar color 使用 sp 檔案 on
- 下載http://smarty.net;
- 解壓 -> 將 libs 檔案夾重新命名 smartyLibs -> 放置在自己伺服器的 usr/local/lib/ 中 (/usr/local/lib/smartyLibs);
- 在網站目錄,如 site_A 中 建立 4 個必須檔案夾 templates、templates_c、configs、cache
//設定許可權chown nginx:nginx "4個目錄";chmod 770 "4個目錄";
- 在網站目錄中建立 smarty.ini.php 設定檔(smarty基本配置資訊),內容如下
<?phpdefine(‘SMARTY_DIR‘,‘/usr/local/lib/smartyLibs/‘);//定義lib路徑require_once(SMARTY_DIR.‘Smarty.class.php‘);//引用Smarty庫$smarty=new Smarty();//建立Smarty$smarty->setTemplateDir(‘./templates‘);$smarty->setCompileDir(‘./templates_c‘);$smarty->setConfigDir(‘./configs‘);$smarty->setCacheDir(‘./cache‘);$smarty->caching=false;//是否使用緩衝//$smarty->testInstall();//調試用,顯示4個目錄可讀寫狀態?>
- 建立網站分頁檔 index.php
<?phpinclude(‘./smarty.ini.php‘);//引用smarty.ini.php設定檔$name=‘YangGe123‘;//自訂變數$smarty->assign(‘name‘,$name);//將變數賦予smarty值‘name‘$smarty->display(‘index.tpl‘);//在templates中引用對應的模板?>
- 在Templates中建立網站對應的模板
<html> <head></head> <body> <h1>{$name}</h1> </body></html>
擴充知識:
調試php,讓伺服器顯示php錯誤資訊:
修改php.ini檔案,將 display_error = off 改為 on
重啟php服務
service php-fpm restart
Nginx.PHP配置Smarty