PHP

Thursday, May 30, 2013

Simple Drupal 7 module

Creating a basic Drupal module is not so hard if you have some knowledge of PHP. All you need is some basic ideas on Drupal directory system. All third party modules are stored in /sites/all/modules/modulename folder. So we are going to create a module and place it there. To run a Module you will need two files "modulename.info" and "modulename.module", note modulename is the name of the module you are going to create.




  1. Create a modulename.info file with the following informaiton
    name = modulename
    description = My first module
    core = 7.x
  2. Now create a modulename.module file with the following content
  3. Go to the module section(http://sitename/admin/modules) you will see the module with a check box before it. Check it and click save button down below.
  4. Go to http://sitename/customurl/firstmodule (same url you defined in modulename_menu function) and you should see the page content as "Hello World".







3 comments:

  1. Do I have to add some data in database while creating new module?

    ReplyDelete
  2. Hi Bipin,

    If your module deals with database then you can create an install file and write the sql script there.
    But, for the above module you do not need to add anything in database.

    Does this answer your question?

    ReplyDelete
  3. Thank you, can i have a sample of code for Simple Drupal 7 module too?

    ReplyDelete