六月婷婷综合激情-六月婷婷综合-六月婷婷在线观看-六月婷婷在线-亚洲黄色在线网站-亚洲黄色在线观看网站

明輝手游網(wǎng)中心:是一個免費提供流行視頻軟件教程、在線學習分享的學習平臺!

說明smarty模板

[摘要]PHP代碼:--------------------------------------------------------------------------------以下的介紹是基于2.5版的,也不知有BUG沒,OS是win2000,php應該4.1以后的就可以。,兄弟只是開發(fā)時使用過幾次,...
PHP代碼:--------------------------------------------------------------------------------



以下的介紹是基于2.5版的,也不知有BUG沒,OS是win2000,php應該

4.1以后的就可以。,兄弟只是開發(fā)時使用過幾次,沒太深的研究,

介紹的在手冊上都能找到,如果有錯誤之處難免多包涵吧


smarty模板據(jù)說是php.net推薦使用的,據(jù)說功能比較強,據(jù)說速度

也不慢,據(jù)說用的人越來越多<img src=http://cfan.net.cn/info/"images/smilies/biggrin.gif" border="0" alt="">

官方網(wǎng)站smarty.php.net上面有論壇,有下載,有手冊。有你想要的一切,切入正題:
(-)安裝:
下載的包解壓后有三個下級目錄:模板文件目錄是<libs> 其下有四個類文件一個目錄.首先介紹最重要的:Smarty.class.php它應該是整個smarty模板的核心類,平時應用時也是跟它打交道,在你的應用程序目錄下建立以下目錄結構:
/app_1/smarty/libs
/app_1/smarty/templates_c
/app_1/smarty/templates
/app_1/smarty/configs

<libs>對應壓縮包下的libs目錄下面放smarty需要的類文件
<templates>存放模板文件,程序用到的模板文件都放這里
<configs>存放模屬性文件,以后詳細說
<templates_c>存放"編譯"后的模板文件,以后詳細說,些目錄需要設為777
<cache>存放緩存的模板文件

以上文件名為smarty默認的文件名,用戶可以指定不同的文件名,如:guest_template_dir,admin_template_dir 等.如果不指定將使用以上文件名
(二)使用:

設計模板:
1模板變量:{$變量名},如 {$color},{$type}
test_color.tpl
<font color={$color}>{$name}</font>
test_url.tpl
<a href="{$url}" target="{$target}">{$title}</a>

2也可以使用模板數(shù)組
test_array.tpl
{people.name}<br>
{people.sex}<br>
{people.money}<br>
3模板使用區(qū)塊列表
如:
user1 user1_sex user1_money
user2 user2_sex user2_money
user3 user3_sex user3_money

section.tpl
可以用表格格式化:
<TABLE>
{section name=user loop=$userList}
<TR>
<TD>{$userList[user].name}</TD>
<TD>{$userList[user].sex}</TD>
<TD>{$userList[user].money}</TD>
</TR>
{/section}
</TABLE>


<?php
//當前目錄app_1下
//生成$smarty實例

require('smarty/lib/Smarty.class.php');
$smarty = new Smarty;

//指定功能目錄,可以自定義
$smarty->template_dir = 'smarty/templates';
$smarty->$compile_dir = 'smarty/template_c';

//為模板變量賦值 模板:color.tpl 放于smarty/templates下
//$smarty->assign('模板變量名','php內(nèi)部變量');
//$smarty->display(模板文件名);

$smarty->assign('color','red');
$smarty->assign('name','hello world');

//顯示模板
//輸出:<font color=red>helloworld</font>
$smarty->display('test_color.tpl');

//為模板數(shù)組變量賦值,模板:test_array.tpl
//輸出:

//巴豆
//男
//a litte
$people = array('name'=>'巴豆','sex'=>'男','money'=>'a little');
$smarty->assign('people',$people);
$smarty->display('test_color.tpl');

//模板區(qū)塊
//{section name=user loop=$userList}
//section:標簽功能
//name:標簽名
//loop:循環(huán)數(shù)組
//功能循環(huán)輸出多行
//輸出:

//user1 user1_sex user1_money
//user2 user2_sex user2_money
//user3 user3_sex user3_money


$userList[] = array('name'=>'user1','sex'=>'user1_sex','money'=>'user1_money');
$userList[] = array('name'=>'user2','sex'=>'user2_sex','money'=>'user2_money');
$userList[] = array('name'=>'user3','sex'=>'user3_sex','money'=>'user3_money');

$smarty->assign('userList',$userList);
$smarty->display('test_section.tpl');
?>
暫時先寫這么點都是最基本的東西了,代碼沒有測試,兄弟初次寫東西有出錯的地方一概不負責。
還有好多有意思的功能以后有機會再寫<img src=http://cfan.net.cn/info/"images/smilies/biggrin.gif" border="0" alt="">



主站蜘蛛池模板: 视频二区 素人 欧美 日韩 | 日本免费看视频 | 亚洲成a人片在线v观看 | 午夜视频体验区 | 五月婷六月婷婷 | 午夜丁香婷婷 | 青青草美女| 做受又硬又粗又免费视频 | 偷拍第一页 | 亚洲福利一区二区精品秒拍 | 伊人五月在线 | 亚洲欧洲综合网 | 色网在线观看 | 伊人网网站 | 天天干天天干天天 | 伊人久久精品成人网 | 青青草视频黄色 | 青青青国产 | 一区二区精品久久 | 天天干在线播放 | 日韩城人视频 | 午夜视频在线免费看 | 日本a黄色片 | 亚洲第一黄色 | 欧洲性生活视频 | 日本大蕉香蕉大视频在线观看 | 青青草手机在线 | 色吊丝最新永久免费观看网站 | 中文字幕午夜乱理片 | 青青青国产高清在线观看视频 | 日本中文字幕乱码免费 | 日韩欧美亚洲综合一区二区 | 深夜福利在线播放 | 青青草免费观看视频 | 日本天堂影院在线播放 | 四虎影永久在线观看精品 | 亚洲成a人片在线观看www | 青青青视频免费 | 最新国产你懂的在线网址 | 欧美一区二三区 | 青免费视频 |