跳至主內容區

XOOPS輕鬆架

:::

主內容區域

選擇後會自動跳轉頁面

7-3 加入確認後刪除的機制

  1. 先在list_action中利用 tadtools內建的 sweet_alert 類別來產生刪除的js函數,以便做出「確認後刪除的功能」:
    //顯示活動列表
    function list_action()
    {
        global $xoopsDB, $xoopsTpl;
    
        $tbl    = $xoopsDB->prefix('actions');
        $sql    = "SELECT * FROM `{$tbl}` WHERE `enable` ='1' AND `end_date` > now() ORDER BY `end_date` DESC";
        $result = $xoopsDB->query($sql) or web_error($sql);
        $myts   = MyTextSanitizer::getInstance();
        while ($action = $xoopsDB->fetchArray($result)) {
            $action['title']   = $myts->htmlSpecialChars($action['title']);
            $action['content'] = $myts->displayTarea($action['content'], 1, 1, 1, 1, 0);
            $actions[]         = $action;
        }
        $xoopsTpl->assign('actions', $actions);
    
        include_once XOOPS_ROOT_PATH . "/modules/tadtools/sweet_alert.php";
        $sweet_alert = new sweet_alert();
        $sweet_alert->render("delete_action", "admin/main.php?op=delete_action&action_id=", 'action_id');
    }
    
  2. render()的第一個參數是js的刪除函數名稱,第二個參數則是執行刪除的路徑,最後一個參數是傳入的編號名稱。
  3. 編輯 templates/tad_signup_index.tpl 樣板,根據身份加入「刪除」按鈕
    <td>
      <{if $isAdmin}>
        <a href="javascript:delete_action(<{$action.action_id}>)" class="btn btn-danger btn-xs">刪除</a>
        <a href="admin/main.php?action_id=<{$action.action_id}>" class="btn btn-warning btn-xs">編輯</a>
      <{/if}>
      <a href="index.php?action_id=<{$action.action_id}>" class="btn btn-info btn-xs">詳情</a>
    </td>
選擇後會自動跳轉頁面

:::

左邊區域內容

書籍目錄

展開 | 闔起

快速登入


右邊區域內容

請掃此 QR Code 可連至此頁面

計數器

今天: 320320320
昨天: 2475247524752475
總計: 9513104951310495131049513104951310495131049513104

頁尾區域