最新xoops模組開發
一、程式
- 流程
default:
# ---- 目前網址 ----
$_SESSION['return_url'] = getCurrentUrl();
$op = "opList";
opList();
break;
- 傳入變數處理
/*-----------執行動作判斷區----------*/
include_once $GLOBALS['xoops']->path('/modules/system/include/functions.php');
$op = system_CleanVars($_REQUEST, 'op', '', 'string');
$sn = system_CleanVars($_REQUEST, 'sn', '', 'int');
- 引入上傳物件
#引入上傳物件
include_once XOOPS_ROOT_PATH . "/modules/ugm_tools2/ugmUpFiles3.php";
二、函數
- opList
#商品列表
function opList() {
global $xoopsDB, $xoopsTpl,$module_name;
#---- 過濾讀出的變數值 ----
$myts = MyTextSanitizer::getInstance();
$sql = "select a.sn,a.title,b.title as kind_title
from " . $xoopsDB->prefix("cnu_show_prod") . " as a
left join " . $xoopsDB->prefix("cnu_show_kind") . " as b on a.kind=b.sn
where a.enable='1'
order by a.`sort` desc,a.`date` desc
"; //die($sql);
//getPageBar($原sql語法, 每頁顯示幾筆資料, 最多顯示幾個頁數選項);
$p_count = 9;
$PageBar = getPageBar($sql, $p_count, 10);
$bar = $PageBar['bar'];
$sql = $PageBar['sql'];
$total = $PageBar['total'];
$bar = $total > $p_count ? $bar : "";
$xoopsTpl->assign("bar", $bar);
$result = $xoopsDB->query($sql) or redirect_header($_SERVER['PHP_SELF'], 3, web_error());
#----單檔圖片上傳
$subdir = "prod"; //子目錄(前後不要有 / )
$ugmUpFiles = new ugmUpFiles($module_name, $subdir); //實體化
$col_name = "prod"; //資料表關鍵字
$thumb = false ; //顯示縮圖
$rows = array();
while ($row = $xoopsDB->fetchArray($result)) {
$row['sn'] = intval($row['sn']);
$row['title'] = $myts->addSlashes($row['title']);
$row['kind_title'] = $myts->addSlashes($row['kind_title']);
$col_sn = $row['sn']; //關鍵字流水號
$row['prod'] = $ugmUpFiles->get_rowPicSingleUrl($col_name,$col_sn,$thumb);
#-----------------------------------
$rows[] = $row;
}
$main['rows'] = $rows;
$main['title'] = "商品展示";
$xoopsTpl->assign("main", $main);
}
三、樣板
<{if $op=="opList"}> <style type="text/css"> .prod-head { padding: 10px; background-color: #333; color:#fff; } .space-10{ height:10px; } .space-20{ height:20px; } .space-30{ height:30px; } .space-40{ height:40px; } .space-50{ height:50px; } .space-60{ height:60px; } /**img**/ .item_holder { background-color: #fff; text-align: center; padding: 15px; position: relative; margin-bottom: 30px; border: 1px solid #eee; -moz-transition: all 0.3s; -o-transition: all 0.3s; -webkit-transition: all 0.3s; transition: all 0.3s; } .item_holder img { display: block; margin: 0 auto; -moz-transition: all 0.3s; -o-transition: all 0.3s; -webkit-transition: all 0.3s; transition: all 0.3s; } .item_holder img:hover { -moz-transform: scale3d(0.95, 0.95, 0.95); -o-transform: scale3d(0.95, 0.95, 0.95); -ms-transform: scale3d(0.95, 0.95, 0.95); -webkit-transform: scale3d(0.95, 0.95, 0.95); transform: scale3d(0.95, 0.95, 0.95); } .item_holder .title { padding-top: 25px; } .item_holder .title h5 { font-size: 14px; font-weight: 600; line-height: 20px; letter-spacing: 1px; font-family: "Open Sans", sans-serif; color: #333; } .item_holder:hover { border-color: #1ab394; } </style> <div class="prod-head"> <h1><{$main.title}></h1> </div> <div class="space-40"></div> <div class="row prod-list"> <{foreach from=$main.rows item=row}> <div class="col-sm-4"> <div class="item_holder"> <a href="<{xoAppUrl}>modules/cnu_show/index.php?op=opShow&sn="<{$row.sn}>> <img src="<{$row.prod}>" alt="<{$row.title}>" class="img-responsive"> </a> <div class="title"> <h5><{$row.title}></h5> <span class="kind"><{$row.kind_title}></span> </div> </div><!--item holder--> </div><!--col end--> <{/foreach}> </div> <{$bar}> <div class="space-60"></div> <{/if}>