一、模板變量賦值 php
$this->assign('name',$value); //或者下面的寫法: $this->name = $value;二、變量輸出
$this->display();三、頁面顯示
{$變量名稱}
<body> <p>用 戶 名:{$username}</p> <p>電子郵件:{$userinfo["email"]}</p> <p>註冊時間:{$userinfo["regdate"]|date="Y-m-d H:i",###}</p> </body>
volist 標籤用於在模板中循環輸出數據集或者多維數組
mod:記錄對mod求餘
$key:顯示數組的key值
$k:顯示對數組循環的次數
offset:從第5條開始循環
length:循環10條數據 html
<table> <volist name="list" id="vo" mod="2" key="k" offset=5 length=10> <tr<eq name="mod" value="0"> style="background-color:#FFF;"</eq>> <td>{$k}{$key}我是單元格內容</td> <td>{$k}{$key}我也是單元格內容</td> </tr> </volist> </table>多維數組循環參考:http://www.5idev.com/p-thinkphp_tpl_volist_nested_loop.shtml
foreach標籤沒有volist標籤那麼多的功能,優點是能夠對對象進行遍歷輸出,而volist標籤一般是用於輸出數組。
thinkphp
<foreach name="list" id="vo"> 用 戶 名:{$vo.username}<br /> 電子郵件:{$vo.email}<br /> 註冊時間:{$vo.regdate|date="Y-m-d H:i",###} <hr /> </foreach>
name 屬性值爲變量名稱,也就是沒有 $ 符號,而 value 值使用變量時須要 $ 符號,case 的 value 屬性能夠支持多個條件的同時判斷,使用 | 符號進行分割 數組
<switch name="uid"> <case value="$adminId">管理員</case> <case value="gif|png|jpeg">圖像格式文件</case> <default />羣衆 </switch>
一、比較標籤 ide
<比較標籤 name="變量名" value="值">輸出的內容</比較標籤>例如:
<eq name="username" value="admin">管理員</eq>二、present標籤、notpresent標籤
<present name="變量名">要輸出的內容</present>notpresent 標籤,爲 present 標籤的反義(即 !isset() )
三、defined標籤、notdefined標籤 函數
<defined name="SITE_NAME">網站名稱:{*SITE_NAME}</defined>
該例子等同於: oop
<?php if(defined("SITE_NAME")){ echo '網站名稱:',constant("SITE_NAME"); } ?>四、empty標籤、notempty標籤
<empty name="username">username 爲空值</empty>
該例子等同於: 佈局
<?php if(empty($username)){ echo 'username 爲空值'; } ?>
根據 empty() 函數咱們知道,以下這些狀況獲得的結果都是 TRUE 的(使用 empty 標籤會有輸出): 網站
//假設要檢測的變量爲 $x $x = ""; $x = null; var $x; $x = array(); $x = false; $x = 0; $x = "0";五、in標籤、notin標籤
<in name="groupId" value="1,2,3">管理羣組</in>
該例子等同於: ui
<?php if(in_array(($groupId), explode(',',"1,2,3"))){ echo '管理羣組'; } ?>六、if...else標籤
<if condition="($vo['uid'] eq 1) OR ($vo['username'] eq 'admin') ">管理員 <elseif condition="$vo['uid'] gt 1" />羣衆 <else />遊客 </if>
condition 屬性裏面還支持直接使用php代碼,例如:
<if condition="strtoupper($vo['username']) eq 'ADMIN' ">管理員 <else />羣衆 </if>
redirect 方法語法以下:
$this->redirect(string url, array params, int delay, string msg)例子:
class IndexAction extends Action{ public function index(){ $this->redirect('select', array('status'=>1), 3, '頁面跳轉中~'); } }
重定向後獲得的 URL 可能爲:http://www.5idev.com/index.php/Index/select/status/1
// 不延時,直接重定向 $this->redirect('select', array('status'=>1)); // 延時跳轉,但不帶參數,輸出默認提示 $this->redirect('select', '', 3); // 重定向到其餘模塊操做 $this->redirect('Public/login'); // 重定向到其餘分組 $this->redirect('Admin-Public/login');success()和error()是經過<meta http-equiv="refresh" content="3">意思是隔3秒鐘後刷新.
方法:
$this->方法名("變量名",["過濾方法"],["默認值"])例子:
$this->_get("name");// htmlspecialchars($_GET["name"]) $this->_get("name","strip_tags"); $this->_get("id","strip_tags",0); $this->_get('id',false);//沒有過濾方法(默認的也不使用)能夠在配置文件中設置默認過濾方法:
'DEFAULT_FILTER'=>'htmlspecialchars,strip_tags'
方法 | 說明 |
---|---|
isGet | 判斷是不是GET方式提交 |
isPost | 判斷是不是POST方式提交 |
isPut | 判斷是不是PUT方式提交 |
isDelete | 判斷是不是DELETE方式提交 |
isHead | 判斷是不是HEAD提交 |
{__CONTENT__}
若是項目須要使用不一樣的佈局模板,能夠動態的配置LAYOUT_NAME參數實現。
若是某些頁面不須要使用佈局模板功能,能夠在模板文件開頭加上 {__NOLAYOUT__} 字符串。
二、以當前輸出模板爲入口的方式
在模板頁中添加
<layout name="layout" />