user2283993
user2283993

Reputation: 13

hook_menu not working on a custom module

May be I am something obvious but a simple custom Hello world module isn't working. I have spent a couple of days trying to fix this but no progress at all.

hello_world.info

name = Hello World
description = "This module is to test hello world"
core = 7.x

hello_world.module

<?php
/**
* Implements hook_init()
*/

function oulta_hello_world_init() {
  drupal_set_message("From Hello World Module");
}

/**
* Implements hook_menu()
*/

function hello_world_menu() {
  $items['hello_world'] = array(
  'title' => 'Just saying hello world',
  'page callback' => 'hello_world_pg',
  'access callback' => TRUE,
  'type' => MENU_CALLBACK,
  );
  return $items;
}

function hello_world_pg() {
  drupal_set_message("Hello World page called");
  return 'Hello world!';
}

I am trying to access the page at localhost/mysite/hello_world/

The path for .module and .info files is htdocs/mysite/sites/all/modules/custom

Since hook_menu is fundamental to development, I am stuck. Please help.

BTW are there are alternatives for hook_menu for rendering pages?

Thanks in advance.

Upvotes: 1

Views: 695

Answers (2)

user2283993
user2283993

Reputation: 13

After trying out myriad solutions, it still didn't work. I came to a conclusion that this was a result of database corruption. Loaded an older database and Voila everything started working.

Upvotes: 0

Muhammad Reda
Muhammad Reda

Reputation: 27023

Change your code to be

function hello_world_menu() {
  $items = array(); // define the $items array

  $items['hello_world'] = array(
  'title' => 'Just saying hello world',
  'page callback' => 'hello_world_pg',
  'access callback' => TRUE,
  'type' => MENU_CALLBACK,
  );
  return $items;
}

And then flush your website cache.

Upvotes: 2

Related Questions