Toggle main menu visibility
新聞
下載
教材
影音
討論
其他選單
好站連結
行事曆
電子相簿
常見問題
萬用表單
即時留言簿
友站消息
社大學員
:::
登入
登入
帳號
密碼
登入
重整畫面
:::
所有書籍
「XOOPS 模組開發」目錄
MarkDown
4. XOOPS的表單物件
1. 開發環境
2. XOOPS模組基本結構
2-1 tad_honor 資料庫結構
2-2 school_news 資料庫結構
2-3 匯出SQL檔的方法
3. 模組管理後台結構
4. XOOPS的表單物件
5. 新增、列出功能
6. XOOPS文字過濾
7. 分頁功能
8. 前台檔案結構
9. 修改、刪除功能
10. 模組偏好設定
11. XOOPS語系功能
12. XOOPS的樣板檔
13. 內建搜尋功能
14. XOOPS的評論功能
15. 製作XOOPS區塊
16. FireFox內建「網頁開發者」工具
16-1 WebDeveloper附加元件
16-2 FireBug附加元件
16-3 用Selenium IDE來測試
17. XOOPS上傳
18. tad_honor 範例
18-1 xoops_version.php
18-2 language/tchinese_utf8/modinfo.php
18-3 sql/mysql.sql
18-4 admin/menu.php
18-5 admin/main.php
18-6 templates/tad_honor_adm_main.html
18-7 index.php
18-8 function.php
18-9 templates/tad_honor_index.html
19. school_news 校園佈告欄範例程式碼
19-1 xoops_version.php
19-2 sql/mysql.sql
19-3 admin/menu.php
19-4 admin/main.php
19-5 templates/school_news_adm_main.html
6. XOOPS文字過濾
XOOPS 模組開發 ========== ### 一、 XOOPS的資料庫物件 1. $xoopsDB是內建的資料庫物件 2. 基本的連線XOOPS已經處理好了 3. 在函數中記得global $xoopsDB; 4. 加入資料表前置字串:$xoopsDB->prefix("資料表") 5. 執行SQL語法:$result=$xoopsDB->query("SQL語法") 6. 抓取資料陣列(名稱索引):$xoopsDB->fetchArray($result) 7. 抓取資料陣列(數字索引):$xoopsDB->fetchRow($result) 8. 最新流水號:$xoopsDB->getInsertId() ### 二、 XOOPS使用者物件:$xoopsUser 1. 取得使用者編號的寫法:$uid=$xoopsUser->uid(); 2. 避免沒登入產生錯誤:$uid=($xoopsUser)?$xoopsUser->uid():0; 3. $xoopsUser物件方法: ``` getVar('uid'):1 //使用者編號 $xoopsUser->getVar('name'):吳大頭 //真實姓名 $xoopsUser->getVar('uname'):tad //登入帳號 $xoopsUser->getVar('email'):tad0616@gmail.com //Email $xoopsUser->getVar('url'):http://localhost/x25/ //個人網站 $xoopsUser->getVar('user_avatar'):avatars/cavt50877193c9788.png //頭像圖片 $xoopsUser->getVar('user_regdate'):1294384702 //註冊日 $xoopsUser->getVar('user_icq'): $xoopsUser->getVar('user_from'): $xoopsUser->getVar('user_sig'): $xoopsUser->getVar('user_viewemail'):1 $xoopsUser->getVar('actkey'): $xoopsUser->getVar('user_aim'): $xoopsUser->getVar('user_yim'): $xoopsUser->getVar('user_msnm'): $xoopsUser->getVar('pass'):56ab24c15b72a457069c5ea42fcfc640 $xoopsUser->getVar('posts'):12 $xoopsUser->getVar('attachsig'):0 $xoopsUser->getVar('rank'):7 $xoopsUser->getVar('level'):5 $xoopsUser->getVar('theme'):school2013 $xoopsUser->getVar('timezone_offset'):8.0 $xoopsUser->getVar('last_login'):1358862705 $xoopsUser->getVar('umode'):thread $xoopsUser->getVar('uorder'):0 $xoopsUser->getVar('notify_method'):1 $xoopsUser->getVar('notify_mode'):0 $xoopsUser->getVar('user_occ'):龍崎國小 $xoopsUser->getVar('bio'): $xoopsUser->getVar('user_intrest'):114620 $xoopsUser->getVar('user_mailok'):0 $xoopsUser->getGroups():Array ?> ``` 4. 以uid取得使用者名稱 ``` $uid_name=XoopsUser::getUnameFromId($uid,1); if(empty($uid_name))$uid_name=XoopsUser::getUnameFromId($uid,0); ``` ### 二、 寫入資料庫 1. PHP的寫法: ``` $sql="insert into `xx_tad_honor` (`honor_year` , `honor_date` , `honor_students` , `honor_descript` , `honor_teachers` , `honor_note`) values('$honor_year' , '$honor_date' , '$honor_students' , '$honor_descript' , '$honor_teachers' , '$honor_note' , '$uid')"; mysql_query($sql) or die(mysql_error()); ``` 2. XOOPS的寫法: ``` $sql="insert into ".$xoopsDB->prefix("tad_honor")." (`honor_year` , `honor_date` , `honor_students` , `honor_descript` , `honor_teachers` , `honor_note` , `uid`) values('$honor_year' , '$honor_date' , '$honor_students' , '$honor_descript' , '$honor_teachers' , '$honor_note' , '$uid')"; $xoopsDB->queryF($sql) or redirect_header('index.php', 3, mysql_error()); ``` ### 三、 列出全部 1. 列出所有資料的SQL語法(幾乎所有撈資料的情形皆可套用,只要修改資料表名稱以及排序欄位即可): ``` $sql="select * from ".$xoopsDB->prefix("tad_honor")." order by `honor_date` desc"; $result=$xoopsDB->queryF($sql) or redirect_header('index.php', 3, mysql_error()); $all_data=""; $i=0; while($all=$xoopsDB->fetchArray($result)){ $all_data[$i]=$all; $i++; } $xoopsTpl->assign("all_data" , $all_data); ``` 2. 其中 $all 是一個陣列,每抓出一筆資料,就會得到下列這樣的陣列: ``` $all['honor_sn']='流水號的值'; $all['honor_year']='學年度的值'; $all['honor_date']='日期的值'; $all['honor_students']='得獎者的值'; $all['honor_descript']='得獎事項的值'; $all['honor_teachers']='指導老師的值'; $all['honor_note']='備註的值'; $all['uid']='發布者的值'; ``` 3. 當我們使用 $all\_data\[$i\]=$all; 後,會產生如下的值(假如抓到三筆資料的話),換言之,當我們多加上一維(現在是二維陣列了)之後,一個 $all\_data 就足以容納所有的資料內容: ``` $all_data[0]['honor_sn']='第1筆資料流水號的值'; $all_data[0]['honor_year']='第1筆資料學年度的值'; $all_data[0]['honor_date']='第1筆資料日期的值'; $all_data[0]['honor_students']='第1筆資料得獎者的值'; $all_data[0]['honor_descript']='第1筆資料得獎事項的值'; $all_data[0]['honor_teachers']='第1筆資料指導老師的值'; $all_data[0]['honor_note']='第1筆資料備註的值'; $all_data[0]['uid']='第1筆資料發布者的值'; $all_data[1]['honor_sn']='第2筆資料流水號的值'; $all_data[1]['honor_year']='第2筆資料學年度的值'; $all_data[1]['honor_date']='第2筆資料日期的值'; $all_data[1]['honor_students']='第2筆資料得獎者的值'; $all_data[1]['honor_descript']='第2筆資料得獎事項的值'; $all_data[1]['honor_teachers']='第2筆資料指導老師的值'; $all_data[1]['honor_note']='第2筆資料備註的值'; $all_data[1]['uid']='第2筆資料發布者的值'; $all_data[2]['honor_sn']='第3筆資料流水號的值'; $all_data[2]['honor_year']='第3筆資料學年度的值'; $all_data[2]['honor_date']='第3筆資料日期的值'; $all_data[2]['honor_students']='第3筆資料得獎者的值'; $all_data[2]['honor_descript']='第3筆資料得獎事項的值'; $all_data[2]['honor_teachers']='第3筆資料指導老師的值'; $all_data[2]['honor_note']='第3筆資料備註的值'; $all_data[2]['uid']='第3筆資料發布者的值'; ``` ### 四、產生XOOPS風格的表格 1. 套用XOOPS的表格風格:<table cellspacing='1' class='outer'>,標題部份:<th class='txtcenter'>分類標題</th>,表格內容部份:<tr class='odd'>或<tr class='even'> ```
學年度
得獎日期
得獎者
得獎事項
指導老師
第1行學年度的內容
第1行得獎日期的內容
第1行得獎者的內容
第1行得獎事項的內容
第1行指導老師的內容
第2行學年度的內容
第2行得獎日期的內容
第2行得獎者的內容
第2行得獎事項的內容
第2行指導老師的內容
``` ### 五、利用Smarty迴圈產生列表內容 1. smarty迴圈的寫法: ``` <{foreach from=$all_data item=data}>
<{$data.honor_year}>
<{$data.honor_date}>
<{$data.honor_students}>
<{$data.honor_descript}>
<{$data.honor_teachers}>
<{/foreach}> ``` 2. 套用上BootStrap後的表格: ```
學年度
得獎日期
得獎者
得獎事項
指導老師
<{foreach from=$all_data item=data}>
<{$data.honor_year}>
<{$data.honor_date}>
<{$data.honor_students}>
<{$data.honor_descript}>
<{$data.honor_teachers}>
<{/foreach}>
``` ### 六、 在樣板中使用判斷式 1. 如果要在同一個樣板,可以選擇性的出現「表單」或者「資料列表」,那麼可以用 <{if}><{elseif}><{else}><{/if}>來做判斷。 ``` <{if $now_op=="honor_form"}> <{elseif $now_op=="honor_modify_form"}> <{else}> <{/if}> ``` 2. 當然,我們需要傳一個樣板變數讓樣板做判斷,例如:$now\_op ### 七、加入後台管理頁面標題 1. 請在頁尾之前加入: ``` include_once XOOPS_ROOT_PATH."/modules/" . $xoopsModule->getVar("dirname") . "/class/admin.php" ; $index_admin = new ModuleAdmin() ; $admin_title=$index_admin->addNavigation('檔名.php') ; $xoopsTpl->assign("admin_title" , $admin_title); ``` 2. 接著在樣板檔套上 <{$admin\_title}> 樣板標籤即可。
:::
搜尋
search
進階搜尋
QR Code 區塊
快速登入
所有討論區
「PHP全端開發」線上課程討論區
XOOPS使用討論區
一般研習學員
社大學員專用
路過哈啦區
XOOPS佈景設計
XOOPS模組開發
Tad書籍區
即時留言簿
書籍目錄
展開
|
闔起
線上使用者
66
人線上 (
16
人在瀏覽
線上書籍
)
會員: 0
訪客: 66
更多…