My hook_menu code is simple as can be and yet I can't get the page to load up. Am I missing something?

function my_module_menu() {
  $items = array();
  $items['mypath'] = array(
    'title' => 'My Page',
    'type' => MENU_CALLBACK,
    'page callback' => 'my_module_page',
  );
}

function my_module_page () {
  return drupal_get_form('my_module_edit_form');
}

Comments

Woggers’s picture

You need to return $items at the end of your hook_menu() over-ride.

attentat’s picture

Saints and Straddle be praised!

drnikki’s picture

with code that works in an clean installation of drupal, but does not work on my development site. I get "page not found" when I try to visit the URL (or when i type in q=front-os-detect)

function gd_homepage_menu() {
 $items = array();
	
 $items['front-os-detect'] = array(
    'title' => t('Gameday Redirect'),
    'description' => t("Redirects based on OS"),
    'page callback' => 'gd_homepage_redirect',
    'access arguments' => array('access content'),
  );
	
  return $items;
}


function gd_homepage_redirect() {
 $os = 'win';
 if(module_exists('gd_helper')) {
  $os = gd_helper_detect_os();
 }
  if($os == 'mac') {
    drupal_goto('home-mac');
  }
  else {
    drupal_goto('home-win');
  }
}

any thoughts? I've uninstalled the module, cleared all caches, re-installed the module and nothing.

gbrussel’s picture

You need to set a type (i.e. MENU_CALLBACK, MENU_NORMAL_ITEM, etc.) for your menu item.

drnikki’s picture

adding 'type' => MENU_CALLBACK doesn't help.

gbrussel’s picture

Does your code look like this?

<?php
  function gd_homepage_menu() {
  $items = array();

  $items['front-os-detect'] = array(
    'title' => t('Gameday Redirect'),
    'description' => t("Redirects based on OS"),
    'page callback' => 'gd_homepage_redirect',
    'access arguments' => array('access content'),
    'type' => MENU_CALLBACK,
  );

  return $items;
}
?>
drnikki’s picture

this is, literally, the whole file.

<?php
// $Id$


/**
 * Implementation of hook_help().
 */
function gd_homepage_help($path, $arg) {
	if ($path == 'admin/help#gd_homepage') {
		return t('<p>Does the thinking for the homepage & where to go.</p>');
	}
}

/**
 * Implementation of hook_menu().
 * Here's a really obscure menu item that will do the redirecting for the home page.
 */
function gd_homepage_menu() {
	$items = array();
	
	$items['front-os-detect'] = array(
    'title' => t('Gameday Redirect'),
    'description' => t("Redirects based on OS"),
    'page callback' => 'gd_homepage_redirect',
    'access arguments' => array('access content'),
    'type' => MENU_CALLBACK,
  );
	
  return $items;
}

function gd_homepage_redirect() {
  $os = 'win';
  if(module_exists('gd_helper')) {
    $os = gd_helper_detect_os();
  }

  if($os == 'mac') {
    drupal_goto('home-mac');
  }
  else {
    drupal_goto('home-win');
  }
}
Cory Goodwin’s picture

I know this post is old but I wanted to post in case someone else comes across this post.

If your code seems to be correct try going to the performance page and clearing the cache. This will fix the problem with page not found and access denied errors during testing (assuming your code is correct).

hrcerqueira’s picture

You're a genius, thank you very much...

exhuma’s picture

I am having the same problem. However, clearing the cache does not work either. Am I missing something in my code? I also checked the database contents (menu_links and menu_router). Even after disabling and re-enabling the module, the links won't show up. Even navigating to "admin/build/modules" does not generate the items.

function minfo_nodes_info_menu() {
  $items = array();

  $items['minfo_nodes/info/find'] = array(
    'title' => 'find_info',
    'description' => 'Find Information nodes',
    'page callback' => 'info_find',
    'access arguments' => array('create minfo_nodes_info'),
    'type' => MENU_CALLBACK,
  );

  return $items;
}

function info_find(){
  return("Hello World!");
}

The module will eventually contain "sub-modules". Hence, hook_info looks like this. Has this anything to do with it? I tried some permutations with the naming of hook_menu, but may have overlooked something.

function minfo_nodes_node_info() {
  return array(
    'info' => array(
      'name' => t('minfo test'),
      'has_title' => false,
      'has_body' => false,
      'module' => 'minfo_nodes_info',
      'description' => "Test",
    )
  );
}
exhuma’s picture

bump

Edward Fox’s picture

Since this has been dug up anyway:

You have to set the type to MENU_NORMAL_ITEM for it to generate a link in the menu structure.

meustrus’s picture

As someone else said, "Since this has been dug up anyway" ...

Your function names look fishy. If your module is called "minfo_nodes" then the function should be called "minfo_nodes_menu". Also make sure to clear the cache after making changes.

teju’s picture

Thanks to DonCoryon. I faced the same problem about hook_menu but after clearing cache the problem is solved.
Thank you once again.......=)

Teju

saemie’s picture

Also make sure you have clean URLs enabled.
You could have a perfectly coded hook_menu implementation but if you try and go to 'my-site.com/path' with clearn URLs disabled you will get a "Page not found" error.

jcgriffiths’s picture

...that you have a view (which is a page) that uses the same URL as you're defining as a key in the $items array.

I had this problem, using Drupal 7, despite the hook_menu() function being correct and having clean URLs functioning properly.

Turns out a view existed already which was using that URL. Unfortunately, there was no error message reporting this conflict, and neither the view nor the hook_menu() implementation overrode each other, and I just got a 404 until I deleted the view.

ShimonDekel’s picture

Had the same problem, but it was unrelated to hook_menu.

I checked the source and it was perfect.

After a while I decided to try clearing the cache using Drush only to get a message that CC had a problem with a second database and did not give any error messages when using the GUI.

Try Drush