thinkphp 使用標籤庫的步驟
來源:互聯網
上載者:User
應用執行個體:在 商務中心的 管理供求資訊 頁面:利用標籤庫產生列表;
步驟一:
在項目設定檔Conf檔案夾下,建立一個taglibs.php檔案,將
return array(
'html'=> '@.TagLib.TagLibHtml' , // 使用import方法支援的路徑格式
);
拷貝進去,這是定義本項目使用哪個標籤庫;
步驟二:
在Lib目錄下,建立 TagLib 檔案夾;
Lib/TagLib/Tags/html.xml 標籤庫的定義檔案;
Lib/TagLib/TagLibHtml.class.php 標籤庫的解析類;
步驟三:
拷貝 CommonAction.class.php 在Action 目錄下;
拷貝 CommonModel.class.php 在Model 目錄下;
步驟四:
lib/Action目錄下;建立一個類:例如:ProductsAction.class.php
class ProductsAction extends CommonAction {
}
如果寫成:
class FormAction extends CommonAction {
//過濾查詢欄位
function _filter(&$map){
$map['title'] = array('like',"%".$_POST['name']."%");
}
}
_filter函數是用來傳遞查詢條件的;
這個地方需要注意:Products必須是對應的資料庫的表名;
步驟五:
在模板中建立一個 Products檔案夾;
index.html 需要包含;
基本的JS檔案;
<load href="__PUBLIC__/Js/Base.js" />
<load href="__PUBLIC__/Js/prototype.js" />
<load href="__PUBLIC__/Js/mootools.js" />
<load href="__PUBLIC__/Js/Ajax/ThinkAjax.js" />
<load href="__PUBLIC__/Js/common.js" />
<load href="__PUBLIC__/Js/Util/ImageLoader.js" />
<script language="JavaScript">
<!--
//指定當前組模組URL地址
var URL = '__URL__';
var APP = '__APP__';
var PUBLIC = '__PUBLIC__';
ThinkAjax.image = [ '__PUBLIC__/images/loading2.gif', '__PUBLIC__/images/ok.gif','__PUBLIC__/images/update.gif' ]
ImageLoader.add("__PUBLIC__/images/bgline.gif","__PUBLIC__/images/bgcolor.gif","__PUBLIC__/images/titlebg.gif");
ImageLoader.startLoad();
//-->
</script>
載入標籤庫:
<tagLib name="html" />
<!-- 列表顯示地區 -->
<div >
<html:list id="checkList" style="list" checkbox="true" action="true" datasource="list" show="id:編號|8%,name:資訊標題:edit,upload_time|toDate='y-m-d':發布日期,checkstatus|getStatus:審核是否通過" actionlist="foreverdel:刪除:id,edit:編輯:id" />
</div>
<!-- 分頁顯示地區 -->
<div class="page">{$page}</div>