views:

42

answers:

1

Hi,

I am trying to add a tab to my menu in drupal and use this function, to test it:

function my_module_menu() {
  $items['user/%user/classifieds'] = array(
    'title' => 'Action',
    'type' => MENU_LOCAL_TASK,
    'page callback' => 'my_module_page',
    'page arguments' => array(1),
    'weight' => 2,
  );
  return $items;
}

But nothing shows up. Why?

+1  A: 

You need an access callback, or at the very least, access arguments (access callback defaults to user_access() if not defined):

function my_module_menu() {
  $items['user/%user/classifieds'] = array(
    'title' => 'Action',
    'type' => MENU_LOCAL_TASK,
    'page callback' => 'my_module_page',
    'page arguments' => array(1),
    'access arguments' => array('access content'),
    'weight' => 2,
  );
  return $items;
}

Also make sure to rebuild the menu or clear the cache when making changes to hook_menu().

Mark Trapp
hmmmm...I used the code you posted, but I still can not see the tab...:(
Lars
I also cleared the cached by emtying all tables with _cache in the name. Also the menu cache (cache_menu), but still no success.
Lars
Is the function `my_module_page` defined, and is it returning a string containing the output for the page? The only thing you need to rebuild when changing `hook_menu` is the menu. [Devel](http://drupal.org/project/devel) lets you do this separately; otherwise, just go to *Site configuration* -> *Performance* and click the *Clear cached data* button.
Mark Trapp
wow. Cool. it is there. It seems that deleting the tables was not enough.Another thing:In D 6 we used this as access argument: 'access' => user_access(TPZCLASSIFIED_PERM_VIEW_PROFILETAB),How do I have to use it in D6?If I use it in the way above, I am not able to see the page because of missing permissions.
Lars
You need to define the permission using [`hook_perm()`](http://api.drupal.org/api/function/hook_perm), which returns an array of strings. Then, you'll be able to use `array('permission name')` for `access arguments`. Just make sure the user has that permission set on *User management* -> *Permissions*.
Mark Trapp

related questions