Tuesday, October 4, 2011

Creating a Basic Drupal Module!

It is quite easy creating a drupal module. The rule what you have to know is just selecting the function you need to use. Because, Drupal has got so many functions that you can use. But before coding, we must create a folder for our module. This folder has two important files:

  1. Mymodule (folder)
    • mymodule.info (must)
    • mymodule.module (must)
    • mymodule.inc
Let's view!


For step 1;

mymodule.info includes;

name = Honda HR-V //this is the name of the module
description = HONDA HR-V car is the best i have ever seen in this world! //the description
package = packageName //which package the module is in
core = 7.x //the core number
version = 7.8 //the version
files[] = honda.module //files that'll include to
dependencies[] = views //the modules which we must include



 
For step 2;

mymodule.module details are;

When we code a module of Drupal, we should know how to use the PHP tags. After the end of our code, we don't put the "<?>" tag on it.

    function honda_menu() {
      $items['honda/hrv'] = array(
        'title' => 'Honda HR-V',
        'page callback' => 'honda_page',
        'access arguments' => array('access content'),
        'file' => 'honda.inc',
      );
      return $items;
    }
    
     Please check "honda/hrv" out. This is the direction we go on the browser. If we click this, it's going to start on "honda.inc" page. Here is one of the most important things we have to know on drupal, is the way of how Drupal's work. "honda_page" is a function actually. When the module opened, this function'll be started.

    For step 3;

    Then let me show you the page which's name is honda.inc:

    function honda_page() {
      return t('This is the first module i created!');
    }
    
    As you see here, we've never used the ending tag ,"? >".
    This honda_page function's been used before When we coding mymodule.module page, page callback.


    By the way, you may ask me what the "t" is. t() is a function that used on drupal. This method handles the outputting works including the multilingual operations.

    If you want to see more information about t() function, you can visit official web site, here is api.drupal.org/t .


    We'll see you next article!

    No comments:

    Post a Comment

    Thanks