2

I am trying to set up a new menu item in Drupal 7 and not having any luck. I've tried several examples and have been successful at this in the past, but this is just not working.

The following code is in a module called directory, I keep getting a "page not found" error.

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

  $items['directory'] = array(
    'title' => 'Employee Directory',
    'page callback' => 'directory_content',
    'access arguments' => array('access content'),
    'type' => MENU_NORMAL_ITEM,
  );

  return $items;    
}

function directory_content() {
  $content = array();

  $content['raw_markup'] = array(
    '#type' => 'markup',
    '#markup' => 'Testing',
  );

  return $content;
}
6
  • Have you installed the module and cleared the caches?
    – Clive
    Commented Apr 29, 2013 at 15:11
  • Also, check this excellent guide on hook_menu()
    – Clive
    Commented Apr 29, 2013 at 15:14
  • Yes, I've cleared the cache and installed the menu. I've checked it and added access callback => TRUE, but it's still not working. Is there some way to debug what's happening when it's adding the menu item? Is there a way to do a dsm item?
    – Sharon
    Commented Apr 29, 2013 at 15:29
  • Yep, just add dsm($item); into the menu hook and flush the caches. If you see your item, the hook is being called, and obviously if not, it's not
    – Clive
    Commented Apr 29, 2013 at 15:32
  • 1
    There doesn't seem to be any problem with your code so it must be something else in your installation. I'd suggest disabling any suspect modules. Also try changing the path and module name from "directory" to something less likely to clash with other code, just in case. Commented Apr 30, 2013 at 8:15

1 Answer 1

0

Your code is working perfectly ok. I installed it you can check the screenshot below. enter image description here

1
  • Thanks to all I got it working - I think it was as @alfreda mentioned - issues with other modules
    – Sharon
    Commented May 7, 2013 at 15:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.