Weitere ähnliche Inhalte
Ähnlich wie [DCTPE2010] Drupal 模組開發入門 (20)
Mehr von Drupal Taiwan (20)
[DCTPE2010] Drupal 模組開發入門
- 14. name = My Module
description = This is my module
core = 6.x
- 16. <?php
function my_module_menu() {
$items['my_module'] = array(
'title' =>'My Module',
'page callback' =>'my_module_page',
'access arguments' =>array('access content'),
'type' =>MENU_NORMAL_ITEM
);
return $items;
}
function my_module_page() {
return 'Hello, this is my module';
}
- 21. <?php
function my_module_install() {
drupal_install_schema('my_module');
}
function my_module_uninstall() {
drupal_uninstall_schema('my_module');
}
function my_module_schema() {
$schema = array(
'my_module' =>array(
'fields' =>array(
'id' =>array('type'=>'serial'),
'name' =>array('type'=>'varchar',
'length'=>'255'),
'email' =>array('type'=>'varchar',
'length'=>'255')
),
'primary key' =>array('id')
),
);
return $schema;
}
- 23. function my_module_page() {
$result = db_query('select * from
my_module');
$rows = array();
while ($data = db_fetch_object($result)) {
$rows[] = array($data->id, $data->name,
$data->email);
}
$headers = array('ID', 'Name', 'Email');
return theme('table', $headers, $rows);
}
- 28. function my_module_form( & $form_state) {
$form = array();
$form['name'] = array(
'#type' =>'textfield',
'#title' =>t('Name'),
);
$form['email'] = array(
'#type' =>'textfield',
'#title' =>t('Email'),
);
$form['submit'] = array('#type'=>'submit',
'#value'=>'Submit');
return $form;
}
function my_module_form_submit($form, & $form_state) {
db_query('insert into my_module values
(null, '%s', '%s')', $form_state['values']['name'],
$form_state['values']['email']);
drupal_goto('my_module');
}
- 32. function my_module_page($arg = 0) {
$arg = intval($arg);
if($arg > 0) {
db_query('DELETE FROM my_module WHERE id = %d',
$arg);
drupal_set_message('Data removed!!!');
}
$result = db_query('select * from my_module');
$rows = array();
while ($data = db_fetch_object($result)) {
$rows[] = array($data->id, $data->name, $data-
>email,
l('Delete', 'my_module/' . $data->id)
);
}
$headers = array('ID', 'Name', 'Email', 'Action');
return theme('table', $headers, $rows) .
drupal_get_form('my_module_form');
}
- 36. 資料檢查、顯示表格的分頁、區分使用者權限、將顯
示分離 ( 樣板 ) 、抽離商業邏輯 (MVC) 、建立自訂內
容類型、使用分類系統、加入 javascript 、與其他模
組互動、加入使用者可調整設定、多國語言、產生區
塊內容、使用佈景元素、系統排程、指令模式、開放
介面、技術文件、操作手冊、教育訓練、功能維護、
版本控制、需求轉換、程式碼的再運用、有事沒事去
看看新模組、新架構、新版本、 ......