2010年5月17日 星期一

ⓒBuild a modules HelloWorld in drupal


在開始前,你必須懂得PHP程式。

步驟一:
在Drupal目錄的modules目錄內建立一個『helloworld』資料夾


步驟二:
建立helloworld.info檔案,貼入以下內容:

;$Id$;
name = Hello World
description = 這是一個"Hello World"的範例模組
core = 6.x




步驟三:
建立helloworld.module檔案,貼入以下內容:

<?php
/********************************
模 組 標 頭
Implementation of hook_help().
********************************/
function helloworld_help($path, $arg) {
    switch ($path) {
        case 'helloworld':
            return '<p>'. t('<strong>模組說明:這是一個HelloWorld的範例模組</strong>') .'</p>';
    }
}
/********************************
永 久 模 組
Implementation of hook_perm().
********************************/
function helloworld_perm() {
    return array('access helloworld');
}
/********************************
模 組 內 容
Implementation of hook_menu().
********************************/
function helloworld_menu() {
    $items = array();
    $items['helloworld'] = array(
        'title' => 'Hello World',
        'description' => 'Hello World!.',
        'page callback' => 'helloworld_all',
        'access arguments' => array('access helloworld'),
        'type' => MENU_NORMAL_ITEM
    );
    return $items;
}
/**
* Creating the page where we will print "Hello World"
*/
function helloworld_all() {
    return t("這是HelloWorld範例的本文內容。");
}
/********************************
區 塊 模 組
Implementation of hook_block().
********************************/
function helloworld_block($op = 'list', $delta = 0, $edit = array()) {
    if ($op == "list") {
        $block = array();
        $block[0]["info"] = t('helloWorld');
        return $block;
    }
    elseif ($op == 'view') {
        $block_content = '<p>這是HelloWorld範例的區塊內容。</p>';
        $block['subject'] = 'Hello World';
        $block['content'] = $block_content;
        return $block;
    }
}
?>


後記:
這篇是站長留下來做個記錄用的,
紅色helloworld是模組改名時要換的,
本模組在Drupal6.16上可運作,

另外Drupal發音似乎是很多人的問題,
站長我之前也不太會念,聽聽看:

以上。

沒有留言: