一、流程
#列表
default:
$op="op_list";
op_list();
break;
二、函數
########################################
# 列表
########################################
function op_list()
{
global $mysqli,$smarty;
#取得所有記錄
$sql = "select *
from `show_kind`
where `kind`='nav_home'
order by `sort` ";
$result = $mysqli->query($sql) or die(printf("Error: %s <br>".$sql, $mysqli->sqlstate));
$DBV=array();
while($row = $result->fetch_assoc())
{
#過濾撈出資料
$row['sn'] = intval($row['sn']);
//http://www.w3school.com.cn/php/func_string_htmlspecialchars.asp
$row['title'] = htmlspecialchars($row['title'], ENT_QUOTES); // 轉換雙引號和單引號
$row['url'] = htmlspecialchars($row['url'], ENT_QUOTES); // 轉換雙引號和單引號
$row['sort'] = intval($row['sort']);
$row['enable'] = $row['enable'] ? "是":"<span style='color:red;'>否</span>";
$row['target'] = $row['target'] ? "是":"<span style='color:red;'>否</span>";
$DBV[]= $row;
}
$smarty->assign("DBV", $DBV);
return;
}
三、樣板
{* 選單管理 列表 *}
{if $WEB.file_name == "nav_m.php" and $op == "op_list"}
<div class="container" style="margin-top:20px;">
<table class="table ">
<thead>
<tr>
<th>標題</th>
<th>網址</th>
<th>外連狀態</th>
<th>啟用狀態</th>
<th>
<button onclick="window.location.href='?op=op_form'" type="button" class="btn btn-primary">新增</button>
</th>
</tr>
</thead>
<tbody>
{foreach from=$DBV item=row}
<tr>
<th>{$row.title}</th>
<th>{$row.url}</th>
<th>{$row.target}</th>
<th>{$row.enable}</th>
<th>
<button onclick="window.location.href='?op=op_show&sn={$row.sn}'" type="button" class="btn btn-warning">瀏覽</button>
<button onclick="window.location.href='?op=op_form&sn={$row.sn}'" type="button" class="btn btn-success">編輯</button>
<button onclick="javascript:op_delete_js({$row.sn});" type="button" class="btn btn-danger">刪除</button>
</th>
</tr>
{/foreach}
</tbody>
</table>
</div>
{/if}