Saturday 19 May 2012

Drupal: Create "hello world" module in drupal 7

This tutorial will show you the easiest way to create a module for drupal 7.

Begin:
  1. Go to 'modules' of drupal 7.
  2. Create 'hello_world' folder.
  3. Create two blank files: hello_world.info and hello_world.module under 'hello_world' under 'hello_world' folder.
  4. Open 'hello_world.info' and enter this content:
    name = Hello World
    description = This is my first module
    core = 7.x
  5. Go to 'Modules' at back-end, You will see your module listed here. Don't enable this module, because we still not finish yet.
  6. Create a menu link to call a page where will show 'hello world'. Open 'hello_world.module' and enter this content:
    function hello_world_menu() {

    $items['hello-world'] = array(


    'title' => 'Hello World',


    'page callback' => 'hello_world',


    'access arguments' => array('access content'),


    );


    return $items;

    }

    function hello_world() {

    return "hello world";

    }
  7. Go to home page and the result will look like this:

Drupal: Readable path

This toturial will show you how to replace the default path of drupal by custom path.
Example:
www.mysite.com/?q=node/add/article => www.mysite.com/?q=create-article
www.mysite.com/?q=node/1 => www.mysite.com/?q=hello-world
Using Path module, you can:

  • Set the path for individual node with the Path module (on the node/add or node edit form).
  • Add a URL alias at 'Administer > Configuration > Search and metadata > URL aliases'  in Drupal 7, 'Administer > Site buiding > URL aliases' in Drupal 6.
You can get more information here: http://drupal.org/documentation/modules/path

Drupal: Installing Drupal on Ubuntu

  1. Download the latest version of drupal here: http://drupal.org/project/drupal
  2. Extract this file into folder: /var/www/
  3. Rename drupal folder: example: Rename 'drupal-7.14' to 'mySite'
  4. Go to: mySite/sites/default . Copy 'default.settings.php' file and rename it to 'settings.php'.
  5. Create an folder called 'files' under: mySite/sites/default/ .
  6. Set permission for 'default' folder:
    sudo chmod 777 -R /var/www/mySite/sites/default/
  7. Go to : localhost/phpmyadmin and create a database. example: create a database called 'mySite'.
  8. Go to : localhost/mySite . It will redirect you to installation page of drupal.
  9. Click on 'Save and continue' button until you redirect to 'Database configuration' page.
  10. Enter you database name, database account and database password. Like this:
    Database name: mySite
    Database account: root
    Database password: ******
  11. After complete the step above, you will redirected to 'Configure site' page. At the page, Enter you site information and then click 'Save and continue'.
  12. Remove write permission on 'settings.php' file.
    sudo chmod a-w /var/www/mySite/sites/default/settings.php
  13. At 'drupal installation complete' page, you click on 'Visit your new site'.
  14. Congratulation, I have installed Drupal success. Let's try to make some great things on your site.