ขอตัวอย่างโค๊ด helloworld ที่มี helloworld_block หน่อยคับ(เพิ่งเริ่มศึกษาคับ)

By lastone040

ขอตัวอย่างโค๊ด helloworld ที่มี helloworld_block หน่อยคับ(เพิ่งเริ่มศึกษาคับ)

6 comments

รูปภาพของ r4vv33
By r4vv33
1 ปี 10 weeks ago

เอา code ที่ไม่มี block

เอา code ที่ไม่มี block ก่อนละกัน

save เป็นไฟล์ชื่อ hello.php เอาไว้ใน / ของ drupal ใช้งานโดย http://yoursite/hello.php

<?php
// Bootstrap Drupal
require 'includes/bootstrap.inc';
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
 
drupal_maintenance_theme();
drupal_set_title(t('Hello, World!'));
print theme('maintenance_page', t('Hello World again.'));
 
?>
By lastone040
1 ปี 10 weeks ago

ขอ helloworld ที่เป็น module

ขอ helloworld ที่เป็น module หนะคับ

รูปภาพของ ball.in.th
By ball.in.th
1 ปี 10 weeks ago

มือใหม่อย่าเพิ่งไปสนใจ case

มือใหม่อย่าเพิ่งไปสนใจ case 'configure': กับ case 'save': ครับ ^ ^

รูปภาพของ r4vv33
By r4vv33
1 ปี 10 weeks ago

module จะประกอบด้วยไฟล์หลัก

module จะประกอบด้วยไฟล์หลัก อย่างน้อย 3 ไฟล์ - .info - .module - .install

ตัวอย่าง module: helloworld จะพิมพ์ข้อความ Hello World ทุกครั้งที่ load page ของเว็บ โดยใช้ function drupal_set_message ผ่านทาง hook_init() ส่วน block จะส่งผ่านทาง hook_block()

ให้ลองหาเอกสารเกี่ยวกับ hook ต่าง ๆ มาศึกษา จะทำให้เข้าใจมากขึ้น

file helloworld.info

; $Id$
name = "Hello World"
description = "Hello world module."
core = 6.x
version = "6.x-0.0"
package = "Hello World"

file helloworld.install

<?php
/**
 * Implements hook_install().
 */
function helloworld_install() {
  // Do nothing..
}
?>

file helloworld.module

<?php
 
/**
 * Implementation of hook_init().
 */
function helloworld_init() {
  drupal_set_message(t('@@ Hello World!!!! @@'));
}
 
/**
 * Implementation of hook_block().
 */
function helloworld_block($op = 'list', $delta = 0, $edit = array()) { 
 
  switch ($op) {
    case 'list':
      $blocks[0]['info'] = t('Hello World');
      return $blocks;
 
    case 'view': 
    default:
      switch ($delta) {
        case 0:
          $block['subject'] = t('Hello World block title');
          $block['content'] = t('Hello world block content');
          break;
      }
      return $block;
  }
 
} 
 
?>
รูปภาพของ ball.in.th
By ball.in.th
1 ปี 10 weeks ago

ชัดเจนครับ ^

ชัดเจนครับ ^ ^
ขอเสริมนิดนึงว่า $delta เอาไว้กรณีที่โมดูลมีหลายๆบล็อค เป็นตัวบอกว่าบล็อคไหนกันแน่ครับ (ตั้งได้ตามใจ)