:::

2-1-1 讓畫面顯示新增活動按鈕

您沒有觀看影片的權限

您沒有觀看影片的權限

請先登入,登入後,確認您的權限後,即可觀看影片。

  1. 預設動作為:
    default:
        if (empty($id)) {
            Tad_signup_actions::index();
            $op = 'tad_signup_actions_index';
        } else {
            Tad_signup_actions::show($id);
            $op = 'tad_signup_actions_show';
        }
        break;

     

  2. 預設執行 Tad_signup_actions::index();
  3. Tad_signup_actions 是類別(class)
  4. :: 是呼叫類別的靜態方法(無須用new去進行實例化)
  5. index()就是類別的靜態方法(函式)
  6. 呼叫 Tad_signup_actions::index();,由該方法透過 $xoopsTpl->assign() 送值到樣板
    //列出所有資料
    public static function index()
    {
        global $xoopsTpl;
    
        $all_data = self::get_all();
        $xoopsTpl->assign('all_data', $all_data);
    }

     

  7. index()則利用類別中的 get_all()來取得該資料表所有值,我們添加一個參數 $only_enable 用來指示是僅列出已啟用(包含未過期活動),還是全部都列出。
    //取得所有資料陣列
    public static function get_all($only_enable = true, $auto_key = false)
    {
        global $xoopsDB;
        
        $and_enable = $only_enable ? "and `enable` = '1' and `action_date` >= now()" : '';
    
        $sql = "select * from `" . $xoopsDB->prefix("tad_signup_actions") . "` where 1 $and_enable";
        $result = $xoopsDB->query($sql) or Utility::web_error($sql, __FILE__, __LINE__);
        $data_arr = [];
        while ($data = $xoopsDB->fetchArray($result)) {
    
            // $data['文字欄'] = $myts->htmlSpecialChars($data['文字欄']);
            // $data['大量文字欄'] = $myts->displayTarea($data['大量文字欄'], 0, 1, 0, 1, 1);
            // $data['HTML文字欄'] = $myts->displayTarea($data['HTML文字欄'], 1, 0, 0, 0, 0);
            // $data['數字欄'] = (int) $data['數字欄'];
    
            if ($_SESSION['api_mode'] or $auto_key) {
                $data_arr[] = $data;
            } else {
                $data_arr[$data['id']] = $data;
            }
        }
        return $data_arr;
    }

     

  8. 因為沒有傳來 $op,所以自定義一個 $op 值(其值一般就是 類別_方法),以便讓樣板引入對應的子樣板。
  9. $op = 'tad_signup_actions_index'; 時,會載入名為 op_tad_signup_actions_index.tpl 的樣板(這不是XOOPS規定的,而是長久開發下來覺得這樣最好維護,也最彈性的作法)
    <h2 class="my">活動列表</h2>
    
    <{if $smarty.session.tad_signup_adm}>
        <div class="bar">
            <a href="index.php?op=tad_signup_actions_create" class="btn btn-primary"><i class="fa fa-plus" aria-hidden="true"></i> 新增活動</a>
        </div>
    <{/if}>

     

  10. 可以用<{$smarty.超級全域變數.索引}> 的方式來取得任何超級全域變數的值。

link to https://github.com/tadlearn/tad_signup/commit/7d8673bb6e83df9e15cbb4c771cee4a6462111ec \


:::

搜尋

QR Code 區塊

https%3A%2F%2Fwww.tad0616.net%2Fmodules%2Ftad_book3%2Fpage.php%3Ftbsn%3D48%26tbdsn%3D1581

書籍目錄

展開 | 闔起

線上使用者

42人線上 (9人在瀏覽線上書籍)

會員: 0

訪客: 42

更多…