Hey, I'm new to drupal module development and I' am having some trouble with the permissions. When I try to access a page that is created by my module, i get a permission denied error unless I am the admin. However, the menu_hook only specifies that you only have the 'view mentors' permission to be able to view the page. (which every group does). Here is my code below:

<?php
function mentor_menu()
{
   
$items = array();
   
$items['test'] = array
    (
       
'title' => 'Find a Mentor',
       
'access arguments' => array('view mentors'),
       
'type' => NORMAL_MENU_ITEM,
    );
    return
$items;
}
?>

I can't figure out what is going wrong. Please help me!
----------------------------------------------------------------------------------

ok, so this is where I am at now. I have taken the advice and I am still getting the permission denied error. (remember, I gave everyone permission to access the page)

<?php
function mentor_menu()
{
   
$items = array();
   
$items['test'] = array
    (
       
'title' => 'Find a Mentor',
       
'description' => 'landing page for module',
       
'page callback' => 'mentor_page',
       
'access arguments' => array('view mentors'),
       
'type' => MENU_NORMAL_ITEM,
    );
    return
$items;
}
?>

OK, I GOT IT WORKING!

It was a really stupid error. I was learning how to build a module and I created a module called "test" module that had a default page of "test." I never got around to finishing it and mostly just played around with it. Even though it wasn't enabled in drupal, it was still reading the permission from the "test" application and was denying all access to the page except to the admin, which essentially holds all the rights possible so it was no big deal. Anyways, thanks for all the help, this has been a learning experience!

Comments

If you copied the above code as-is from your module, you have an error. The "type" value is not a valid constant. you want "MENU_NORMAL_ITEM" instead.

---------------------------------
Steven Wright

I have to disagree with that. He is using it correctly. MENU_NORMAL_ITEM is a constant. See hook_menu() under the 'type' section.

As to the original problem - you haven't defined a page callback, so there is no function to be called when accessing the URL.

Jaypan
Our newest Drupal site: PacificAikido.com (Drupal showcase)

stevenc is right, john has an error in typing. It is not NORMAL_MENU_ITEM, it is MENU_NORMAL_ITEM.
Also, as Jay says, you should have a "page callback" to be called when somebody accesses the menu.

Vasi.

Ahh, I misread what he said. I thought he was saying it needs quotes.

Jaypan
Our newest Drupal site: PacificAikido.com (Drupal showcase)

I changed the type to be the MENU_NORMAL_ITEM however it is still not working. I did not use a callback function because it should default to user_access() as defined by the documentation.

Thanks!
John Murray

ok, so I added menu callback and I'm still getting the same error. Here is what my code is now. keep in mind that the user I am trying to access the page with has the only permission that it requires to view the page. In fact, I gave that permission to all users, even anonymous users.

function mentor_menu()
{
$items = array();
$items['test'] = array
(
'title' => 'Find a Mentor',
'page callback' => 'mentor_page',
'access arguments' => array('view mentors'),
'type' => MENU_NORMAL_ITEM,
);
return $items;
}

Thanks!
John Murray

Did you clear your cache after adding that code? hook_menu() is cached, so any changes will not be reflected until you clear the cache.

Jaypan
Our newest Drupal site: PacificAikido.com (Drupal showcase)