#列表
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
".$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'] ? "是":"否";
$row['target'] = $row['target'] ? "是":"否";
$DBV[]= $row;
}
$smarty->assign("DBV", $DBV);
return;
}
```
三、樣板
```
{* 選單管理 列表 *}
{if $WEB.file_name == "nav_m.php" and $op == "op_list"}
標題 |
網址 |
外連狀態 |
啟用狀態 |
|
{foreach from=$DBV item=row}
{$row.title} |
{$row.url} |
{$row.target} |
{$row.enable} |
|
{/foreach}
{/if}
```