程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 網頁編程 >> PHP編程 >> PHP綜合 >> smarty 學習筆記

smarty 學習筆記

編輯:PHP綜合
作用:美工與後台編程分離,加快訪問速度
smarty_inc.php        配置文件 <?PHP
/*smarty模板
*$smarty->assign("模板變量","值(數組、變量)");
*$smarty->display("模板名稱"); *$smarty->assign("name","PHP100中文");進行模板變量的替換
*$smarty->display("index.htm");該文件就是模板文件,應該在模板目錄下
*<title>{$name}</titke> * include_once("smarty/Smarty.class.PHP");
$smarty=new Smarty();
$smarty->config_dir="Smarty/Config_File.class.PHP";//目錄變量
$smarty->caching=false;//是否使用緩存
$smarty->template_dir="./templates";//模板目錄
$smarty->compile_dir="./templates_c";//設置編譯目錄
$smarty->cache_dir="./smarty_cache";//緩存文件夾
$smarty->left_delimiter="{";
$smarty->right_delimiter="}";
//左右邊界符,默認為{}但是實際當中容易與Javascript相沖突
//{}之間寫的就是Html中PHP的內容變量
?> index.php <?PHP
include("smarty_inc.PHP"); $title="this is my page";
//$name二維數組
$name[]=array("a"=>"aaa","b"=>"bbb");
$name[]=array("a"=>"AAA","b"=>"BBB");
$name[]=array("a"=>"111","b"=>"222");
$smarty->assign("title",$title);
$smarty->assign("name",$name); $smarty->display("index.htm");//指定哪個模板顯示
?> templates/index.htm <title>{$title}</title>
<body>
<h1>{$title}</h1>
{section name=list loop=$name}
{$name[list].a}---{$name[list].b} <br/> {sectionelse} {/section}
</body> =======================
當訪問index.PHP時候 1.template_c文件夾有一個自動生成的Html與PHP混合編譯好的文件
2.如圖結果

smarty 學習筆記


  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved