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:

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)


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

stevenc’s picture

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

Slalom

Jaypan’s picture

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.

vasi1186’s picture

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.

Jaypan’s picture

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

johnmurray’s picture

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.

johnmurray’s picture

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;
}
Jaypan’s picture

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.