:::

8. XoopsModules\Tadtools\TadDataCenter 資料中心

use XoopsModules\Tadtools\TadDataCenter;

建立資料表

CREATE TABLE `模組名稱_data_center` (
    `mid` mediumint(9) unsigned NOT NULL AUTO_INCREMENT COMMENT '模組編號',
    `col_name` varchar(100) NOT NULL DEFAULT '' COMMENT '欄位名稱',
    `col_sn` mediumint(9) unsigned NOT NULL DEFAULT '0' COMMENT '欄位編號',
    `data_name` varchar(100) NOT NULL DEFAULT '' COMMENT '資料名稱',
    `data_value` text NOT NULL COMMENT '儲存值',
    `data_sort` mediumint(9) unsigned NOT NULL DEFAULT '0' COMMENT '排序',
    `col_id` varchar(100) NOT NULL COMMENT '辨識字串',
    `sort` mediumint(9) unsigned COMMENT '顯示順序',
    `update_time` datetime NOT NULL COMMENT '更新時間',
    PRIMARY KEY (
        `mid`,
        `col_name`,
        `col_sn`,
        `data_name`,
        `data_sort`
    )
) ENGINE = MyISAM DEFAULT CHARSET = utf8;

產生單一個表單欄位:

$TadDataCenter = new TadDataCenter($module_dirname);
$TadDataCenter->set_col($col_name, $col_sn);
$form = $TadDataCenter->getForm($mode, $form_tag, $name, $type, $value, $options, $attr, $sort);

 

產生批次表單欄位:

$TadDataCenter = new TadDataCenter($module_dirname);
$TadDataCenter->set_col($col_name, $col_sn);
$TadDataCenter->assignBatchForm($form_tag, $data_arr = array(), $type = '', $attr = []);

 

儲存資料:

$TadDataCenter = new TadDataCenter($module_dirname);
$TadDataCenter->set_col($col_name, $col_sn);
$TadDataCenter->saveData();
// 或
$data_arr = [
    $data_name1 => [0 => $data_value1, 1 => $data_value2],
    $data_name2 => [0 => $data_value3],
];
$TadDataCenter->saveCustomData($data_arr = []);

 

取得資料陣列:

$TadDataCenter = new TadDataCenter($module_dirname);
$TadDataCenter->set_col($col_name, $col_sn);
$data = $TadDataCenter->getData($name, $sort = 0);
$xoopsTpl->assign('data', $data);

$data是二維陣列:$data['變數名稱1'][0]$data['變數名稱1'][1]...

 刪除資料:

$TadDataCenter = new TadDataCenter($module_dirname);
$TadDataCenter->set_col($col_name, $col_sn);
$TadDataCenter->delData($name, $sort);

 

eguide 語法相關

 

eguide 語法文字轉表單:

$TadDataCenter = new TadDataCenter($module_dirname);
$data = strToForm($setup = '');

$data 完整表單字串

取得所有的欄位設定:

$TadDataCenter = new TadDataCenter($module_dirname);
$data = getAllCols($setup);

$data是二維陣列

取得所有欄位的某個項目值:

$TadDataCenter = new TadDataCenter($module_dirname);
$data = $TadDataCenter->getAllColItems($setup, $item = 'label');

$data是一維陣列,索引值是 label

取得某一欄位設定:

$TadDataCenter = new TadDataCenter($module_dirname);
$data = $TadDataCenter->getColSetup($setup);

$data 是一維陣列,包括:

  • $data['form_tag']
  • $data['label']
  • $data['type']
  • $data['value']
  • $data['options']
  • $data['attrs']
  • $data['other']
  • $data['help']
  • $data['require']
  • $data['kind']

 


:::

搜尋

QR Code 區塊

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

書籍目錄

展開 | 闔起

線上使用者

17人線上 (5人在瀏覽線上書籍)

會員: 0

訪客: 17

更多…