:::

3-1-1 取得所有活動資料

您沒有觀看影片的權限

您沒有觀看影片的權限

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

  1. index.php 預設沒有 $op 時,會執行default,當沒有指定 $id 時,則執行顯示所有資料,也就是 Tad_signup_actions::index()
    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. class/Tad_signup_actions.php 中的 Tad_signup_actions 類別下的 index() 可以看出,主要的資料來源是從 get_all() 取得的
    //列出所有資料
    public static function index()
    {
        global $xoopsTpl;
    
        $all_data = self::get_all();
        $xoopsTpl->assign('all_data', $all_data);
    }

     

  3. 所以我們稍微調整一下 get_all() 的內容,也就是設定一些過濾動作而已
    //取得所有資料陣列
    public static function get_all($only_enable = true, $auto_key = false)
    {
        global $xoopsDB;
        $myts = \MyTextSanitizer::getInstance();
    
        $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['title'] = $myts->htmlSpecialChars($data['title']);
            $data['detail'] = $myts->displayTarea($data['detail'], 0, 1, 0, 1, 1);
            $data['setup'] = $myts->displayTarea($data['setup'], 0, 1, 0, 1, 1);
    
            if ($_SESSION['api_mode'] or $auto_key) {
                $data_arr[] = $data;
            } else {
                $data_arr[$data['id']] = $data;
            }
        }
        return $data_arr;
    }

     

link to https://github.com/tadlearn/tad_signup/commit/f868d469e655a610d4de08fc2734a0b8d41a2b3e


:::

搜尋

QR Code 區塊

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

書籍目錄

展開 | 闔起

線上使用者

19人線上 (2人在瀏覽線上書籍)

會員: 0

訪客: 19

更多…