Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
By parogne on
I want to find a basic "Hello World" module to start working on Drupal 7. Can anyone help please?
Thank you for your time.
Comments
_
See http://drupal.org/handbook#code
Bare Bones Drupal 7 Hello World Module
Hi,
I am assuming you have successfully installed Drupal 7. Here is a bare bones "Hello World" module.
File: /sites/all/modules//mymodule/mymodule.module
Note! I created a subdirectory called "mymodule".
File: /sites/all/modules/mymodule/mymodule.info
Install the module through the Admin Modules interface (dashboard). The new module will probably be listed at the very bottom of the admin/modules page.
Use the Admin Performance function and clear all cache. That will make sure Drupal recognizes the map to your function (Drupal jargon for request mapper is "Menu").
To invoke hello world go to : http://mysite/my_module/hello_world
Hope that helps.
THANK YOU
I do have D7 installed, I am having a little bit of trouble with getting this module to display but I will keep tweaking and get it worked out. Do I need to have clean URL activated to get it to go to the /my_module/hello_world address?
Basic Drupal URL Mapping
No, you don't need to turn on any clean URL's. Drupal refers to url mapping (request dispatcher) as a "Menu". The function "mymodule_menu()" maps the url "my_module/hello_word" to the say_hello_world() function.
Drupal also uses "module" names as a pseudo name space. Therefore make sure that you create the subdirectories and file names exactly as described in my example.
You must clear the "cache" in order for Drupal to recognize the url map.
Is the say_hello_world() function being called? is there a specific reason why you need a "hello world" module for Drupal 7 and not Drupal 6?
You might want to check a series of blog posts I put together for beginning Drupal developers. Takes you step by step on how to create a simple module. The hello world module in this thread contains less functionality, however this may help (note! blog posts for Drupal 6).
What the sample module will do:
http://public-action.org/content/drupal-beginners-programming-create-sim...
Creating the files and sub-directories:
http://public-action.org/content/drupal-beginners-programming-creating-s...
Finally the completed code:
http://public-action.org/content/drupal-beginners-programming-create-sim...
Hope that helps.
Thanx a lot...but i am not
Thanx a lot...but i am not getting the term "$items['my_module/hello_world']", when i run the module i write in the url as
localhost/my_module/hello_world...how this work i cant understand.
hook_menu puts
hook_menu puts 'my_module/hello_world' string in to menu_router database table along with corresponding function to call when this URL is accessed.
in .htaccess (placed in Drupal's root folder) there is definition which puts everything after host in to $_GET['q'] variable and calls index.php file. for example:
http://yourdomain.com/my_module/hello_world
becomes:
http://yourdomain.com/index.php?q=my_module/hello_world
index.php performs thousands of operations called bootstrap process, during this process Drupal uses $_GET['q'] variable to get name of the function to call from menu_router table and calls your function.
Thanx for reply me. But when
Thanx for reply me.
But when i am changing the code by any thing as like "$items['anything']" instead of "$items['my_module/hello_world']",
then also my module is runing by url localhost/my_module/hello_world. how is happing it i am not getting ?
my code is and in this code line number 3 i am not getting
-------------------------------------------------------
function mymodule_menu() {
$items = array();
$items['my_module/hello_world'] = array(
'title' => 'Hello World Test',
'page callback' => 'say_hello_world',
'access arguments' => array('access content'),
'type' => MENU_CALLBACK,
);
return $items;
}
When you change the path
When you change the path 'mymodule/hello_world' the menu router needs to be rebuilt to pick up the new URL. Until you do that Drupal is still relying on the old path. To do this you can reinstall the module or better you should get the devel module. It will provide a block with a bunch of useful links for development. You can use the rebuild menus link to rebuild the menu router. Use
$items['admin/something']
to make an item appear in the administration menu. In other words, normal menu items items prepended withadmin/
go in the admin menu.If new to drupal try videos at https://buildamodule.com
Hey, perfect for beginners wanting to do a hello world module to learn.... Try the free videos at https://buildamodule.com. Click videos at the top. Some are for free. The ones you want just happen to be free teaser videos. Click Drupal 7 Development Core Concepts. There is a wonderful set of videos to explain a hello world module and line by line explanation for the .info and .module files.
How to create custom Module in drupal ?
the best example how to create Drupal module programatically.
check it >> http://www.letmecrazy.com/drupal8-how-create-custom-block-programatically/