:::

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>

:::

書籍目錄

展開 | 闔起

https%3A%2F%2Fcampus-xoops.tn.edu.tw%2Fmodules%2Ftad_book3%2Fpage.php%3Ftbsn%3D29%26tbdsn%3D891

計數器

今天: 927927927
昨天: 3438343834383438
總計: 7391256739125673912567391256739125673912567391256