Title1

Title2

Title3

5-2 smarty 樣版

在樣版裡,我們可以透過Smarty預先定義好的變數,以存取PHP中的全域變數(SuperGlobals)

Smarty 保留變數 等同的PHP變數
$smarty.get $_GET
$smarty.post $_POST
$smarty.request $_REQUEST
$smarty.session $_SESSION
$smarty.cookies $_COOKIE
$smarty.env $_ENV
$smarty.server $_SERVER
$smarty.const 利用define函式定義的常數
  1. 得到陣列的數量:<{$array|@count}>
  2. 刪除快取:    $smarty->clearAllCache();
  3. <{foreach from=$teams item=team name=team_f}>   <{/foreach}>
    $teams 來自後台 $smarty->assign("teams", 變數 or 陣列);
    將foreach 命名為「team_f」
    <{$smarty.foreach.team_f.first}> :第1次執行 foreach迴圈
    <{$smarty.foreach.team_f.last}> :最後1次執行 foreach迴圈
    <{$smarty.foreach.team_f.iteration}> :取得迴圈的計數值,依序輸出1、2、3......
    <{$smarty.foreach.team_f.total}> :取得迴圈執行總數,等同<{$array|@count}>

    <{assign var=conuter value=$smarty.foreach.n.total+1}>
    <{$conuter}>. 
  4. 範例:
    
    <{foreach from=$rows item=row key=id name=t}>
    	<{if $smarty.foreach.t.first}>
    		<tbody id='sort'>
    	<{/if}>          
    		<tr id='tr_<{$row.sn}>'>
    			<td class="text-center"></td>
    			<td class="text-center"><{$row.date}></td>
    			<td class="text-center"><{$row.title}></td>
    			<td class="text-center"><{$row.kind_title}></td>
    			<td class="text-center">
    				<{if $row.enable}>
    					<a href='?op=op_update_enable&sn=<{$row.sn}>&enable=0' atl='<{$smarty.const._MD_UGMMODULE_ENABLE_0}>' title='<{$smarty.const._MD_UGMMODULE_ENABLE_0}>'><img src='<{$xoops_url}>/modules/<{$DIRNAME}>/images/on.png' /></a>
    					<{else}>
    					<a href='?op=op_update_enable&sn=<{$row.sn}>&enable=1' atl='<{$smarty.const._MD_UGMMODULE_ENABLE_1}>' title='<{$smarty.const._MD_UGMMODULE_ENABLE_1}>'><img src='<{$xoops_url}>/modules/<{$DIRNAME}>/images/off.png' /></a>
    				<{/if}>                
    			</td>
    			<td class="text-center">
    				<a href="?op=op_form&sn=<{$row.sn}>" class="btn btn-success btn-xs"><{$smarty.const._EDIT}></a>
    				<a href="javascript:op_delete_js(<{$row.sn}>);" class="btn btn-danger btn-xs"><{$smarty.const._DELETE}></a> 
    			</td>
    		</tr>
    	<{if $smarty.foreach.t.last}>            
    		</tbody>
    	<{/if}>
    <{/foreach}>

     

  5.