Counter: 1105,
today: 5,
yesterday: 8
waffleをカスタマイズする際のTIPSを書いています。
データアクセス ↑
前処理 ↑
<?php
require_once('../../../mainfile.php');
require_once(XOOPS_ROOT_PATH . '/modules/waffle0/include/WaffleMAP.php');
$dbmap = WaffleMAP::new_with_cache('waffle0_data1.yml');
$list = $dbmap->get_all();
最低限、include/WaffleMAP.php を読み込む必要がある。
テーブルのデータを全て取得する ↑
<?php
require_once('../../../mainfile.php');
require_once(XOOPS_ROOT_PATH . '/modules/waffle0/include/WaffleMAP.php');
$dbmap = WaffleMAP::new_with_cache('waffle0_data1.yml');
$list = $dbmap->get_all();
以降、require_once 等前処理は省略。
アップデート ↑
$arr = array('t1_id' => 1,
't1_c1' => 'テスト',
't1_c2' => strftime("%Y-%m-%d %H:%M:%S"),
't1_c3' => $count);
$dbmap->update($arr);
プライマリキー(ここでは t1_id)は指定必須。
1行だけ取得する ↑
$row = $dbmap->get_row($id);
プライマリキー = $id の行を一行返す。
1件、1カラムだけデータを取得する ↑
$name = $dbmap->get_one('t1_c2', 't1_id = ' . intval($id));
t1_id = $id の条件に該当する行の t1_c2 カラムを返す。
条件SQLの WHERE区になる。
行数を返す ↑
$count = $dbmap->get_count('t1_c9 > 10');
条件に該当する行数を返す。
条件はSQLのWHERE区になる。
waffleモジュールが管理しているテーブル以外を操作する ↑
XOOPS の users テーブルを操作する ↑
waffle0/yaml/users.yml を作成する。
内容
#
name: users
desc: ユーザテーブル
columns:
- name: uid
desc: ID
type: integer
primary_key: yes
serial: yes
listview: yes
- name: name
desc: 名前
type: string
not_null: yes
maxlength: 254
size: 40
listview: yes
- name: uname
desc: 名前
type: string
not_null: yes
maxlength: 254
size: 40
listview: yes
- name: email
desc: メール
type: string
not_null: yes
maxlength: 254
size: 40
listview: yes
users.yml を指定して WaffleMAP クラスを使う。
<?php
require_once('../../mainfile.php');
require_once(XOOPS_ROOT_PATH . '/modules/waffle0/include/WaffleMAP.php');
$dbmap = WaffleMAP::new_with_cache('users.yml');
$list = $dbmap->get_all();
print_r($list);
その他 ↑
カラム型を追加する ↑
新しいカラムを追加する。
この辺に追記。
- config.php
- include/WaffleMAP.php の validate()
- template/waffle0_ddcommon_list.html
- template/waffle0_ddcommon_view_one.html
- template/waffle0_ddcommon_form.html
必要ならば
db2yaml.php
テーブル名を得る ↑
index.php
$map = WaffleMAP::new_with_cache($dd . '.yml');
の後ろに
$xoopsTpl->assign('table_desc', $map->yaml['desc']);
を追加。
テンプレート中で <{$table_desc}> で表示できる。
プログラム中でプルダウンの選択肢を得る ↑
一例
$tmp = $map->column_map['t3_c11']['enum'];
