摘要:最近由于工作的原因,不得不對(duì)ECShop進(jìn)行研究和二次開(kāi)發(fā),記錄一下筆記文檔。方式調(diào)用的,所以對(duì)于剛接觸該系統(tǒng)的人在研究這個(gè)功能時(shí),往往比較費(fèi)力。。??戳撕脦滋炜偨Y(jié)一下步驟:1.先寫(xiě)一個(gè)functio...
最近由于工作的原因,不得不對(duì)ECShop進(jìn)行研究和二次開(kāi)發(fā),記錄一下筆記文檔。
由于Ecshop后臺(tái)分頁(yè)和搜索是用ajax方式調(diào)用的,所以對(duì)于剛接觸該系統(tǒng)的人在研究這個(gè)功能時(shí),往往比較費(fèi)力。。??戳撕脦滋炜偨Y(jié)一下步驟:
1.先寫(xiě)一個(gè)function get_page_list() 函數(shù),里面要包括可以進(jìn)行排序,分頁(yè),查詢等功能
2.在php文件里面寫(xiě)一個(gè)elseif ($_REQUEST['act'] == 'list') ,這里是顯示默認(rèn)分頁(yè)數(shù)據(jù)
3.在php寫(xiě)一個(gè)elseif($_REQUEST['act'] == 'query')的邏輯,(listtable.js默認(rèn)的是先讀取$_REQUEST['act'] == 'query')排序、分頁(yè)、查詢都在query里面完成
4.html頁(yè)面
實(shí)例:
1.先寫(xiě)一個(gè)function get_page_list,可以進(jìn)行排序、分類、查詢。
/** * 獲取分頁(yè)列表 * * @access public * @return array */ function get_page_list(){ //獲取上一次保存的查詢條件 $result = get_filter(); if ($result === false){ //搜索條件 $where = ' where 1=1 '; $filter = array(); //ajax搜索功能 if (isset($_REQUEST['is_ajax']) && $_REQUEST['is_ajax'] == 1){ $is_import = isset($_REQUEST['is_import']) ? intval($_REQUEST['is_import']) : 99; $keyword = isset($_REQUEST['keyword']) ? trim($_REQUEST['keyword']) : ''; $filter['is_import'] = $is_import; $filter['keyword'] = json_str_iconv($keyword); if($is_import != 99) $where .= "and is_import = $is_import "; if(!empty($filter['keyword'])) $where .= "and goods_name like '%$keyword%' "; } /* 記錄總數(shù)以及頁(yè)數(shù) */ $sql = "SELECT COUNT(*) FROM ".$GLOBALS['cy']->table('jz_goods').$where; $filter['record_count'] = $GLOBALS['db']->getOne($sql); //分頁(yè)大小 $filter = page_and_size($filter); //處理后$filter數(shù)組里有:record_count,page_size,page,page_count,start /* 查詢記錄 */ $sql = "SELECT * FROM ".$GLOBALS['cy']->table('jz_goods').$where." ORDER BY id DESC LIMIT " . $filter['start'] . ',' . $filter['page_size'];; //保存查詢條件(cookie保存) set_filter($filter, $sql); }else{ $sql = $result['sql']; $filter = $result['filter']; } $depot_list = $GLOBALS['db']->getAll($sql); //組合成系統(tǒng)默認(rèn)查詢條件 return array('depot_list' => $depot_list, 'filter' => $filter, 'page_count' => $filter['page_count'], 'record_count' => $filter['record_count']); }
2.php列表文件:
elseif ($_REQUEST['act'] == 'list'){ $smarty->assign('ur_here', '測(cè)試'); $smarty->assign('full_page', 1); $page_list = get_page_list(); $smarty->assign('data', $page_list['depot_list']); $smarty->assign('filter', $page_list['filter']); $smarty->assign('record_count', $page_list['record_count']); $smarty->assign('page_count', $page_list['page_count']); assign_query_info(); $smarty->display('import_list.htm'); } /*------------------------------------------------------ */ //-- 排序、分頁(yè)、查詢 /*------------------------------------------------------ */ elseif ($_REQUEST['act'] == 'query') { $page_list = get_page_list(); $smarty->assign('data', $page_list['depot_list']); $smarty->assign('filter', $page_list['filter']); $smarty->assign('record_count', $page_list['record_count']); $smarty->assign('page_count', $page_list['page_count']); make_json_result($smarty->fetch('import_list.htm'), '',array('filter' => $page_list['filter'], 'page_count' => $page_list['page_count'])); }
3.HTML模板文件:
{if $full_page} {include file="pageheader.htm"} {insert_scripts files="../js/utils.js,listtable.js"} {include file="goods_search_other.htm"} <form method="post" action="" name="listForm"> <div class="list-div" id="listDiv"> {/if} <table cellpadding="3" cellspacing="1" class="table table-bordered"> <tr> <th><input onclick='listTable.selectAll(this, "checkboxes")' type="checkbox"></th> <th>商品圖片</th> <th>商品名稱</th> <th>商品ID</th> <th>品牌名稱</th> <th>分類名稱</th> <th>銷售價(jià)</th> <th>庫(kù)存數(shù)</th> <th>已導(dǎo)入</th> <th>操作</th> </tr> {foreach from=$data item=goods} <tr> <td><input value="{$goods.id}" name="checkboxes[]" type="checkbox"></td> <td><img src="{$goods.goods_img}" height="70"></td> <td>{$goods.goods_name}</td> <td>{$goods.goods_id}</td> <td>{$goods.brand_name}</td> <td>{$goods.cate_name}</td> <td>{$goods.sell_price}</td> <td>{$goods.store_nums}</td> <td>{if $goods.is_import eq 1}是{else}<span style="color:red">否</span>{/if}</td> <td align="center"> <a href="javascript:;" onclick="remove_jz({$goods.id})" title="刪除">刪除</a> </td> </tr> {foreachelse} <tr><td class="no-records" colspan="10">{$lang.no_records}</td></tr> {/foreach} <tr> <td align="right" nowrap="true" colspan="6"> {include file="page.htm"} </td> </tr> </table> {if $full_page} </div> </form> <script type="text/javascript" language="javascript"> listTable.recordCount = {$record_count}; listTable.pageCount = {$page_count}; {foreach from=$filter item=item key=key} listTable.filter.{$key} = '{$item}'; {/foreach} function remove_jz(id){ if(confirm('確定刪除嗎?')){ window.location.href = "jiangzi.php?act=remove&id="+id; } } </script> {include file="pagefooter.htm"} {/if} goods_search_other.htm文件: <div class="form-div"> <form action="javascript:searchGoods()" name="searchForm" > <img src="images/icon_search.gif" width="26" height="22" border="0" alt="SEARCH" /> {if $smarty.get.act neq "trash"} <select name="is_import"><option value='99'>是否導(dǎo)入</option><option value="1">是</option><option value="0">否</option></select> {/if} 商品名稱 <input type="text" name="keyword" size="15" /> <input type="submit" value="{$lang.button_search}" class="button" /> </form> </div> {literal} <script language="JavaScript"> function searchGoods() { {/literal} {if $smarty.get.act neq "trash"} //listTable.filter['cat_id'] = document.forms['searchForm'].elements['cat_id'].value; listTable.filter['is_import'] = document.forms['searchForm'].elements['is_import'].value; {/if} {literal} listTable.filter['keyword'] = Utils.trim(document.forms['searchForm'].elements['keyword'].value); listTable.filter['page'] = 1; listTable.loadList(); } </script> {/literal}
說(shuō)明:{literal}{/literal}是smarty標(biāo)簽,當(dāng)smarty的邊界符定義為{} (大括號(hào))的時(shí)候~{literal}{/literal}是用來(lái)忽略該標(biāo)簽內(nèi)的大括號(hào)的。
網(wǎng)友評(píng)論:
2017-07-25 09:31:27 回復(fù)
網(wǎng)友評(píng)論:
測(cè)試
2017-06-20 16:30:25 回復(fù)